-
Hello, I am trying to modify a structure, so that it only contains sugar residues with either import gemmi
from pathlib import Path
def write_structure(input_structure: Path, output_path: Path) -> None:
structure = gemmi.read_structure(str(input_structure))
structure.setup_entities()
to_remove = []
for model_idx, model in enumerate(structure):
for chain_idx, chain in enumerate(model):
for residue_idx, residue in enumerate(chain):
# simplified example of removing residues/atoms
# in my code I filter by altloc value on the level of atoms
if residue.name == "GLC":
to_remove.append([model_idx,chain_idx,residue_idx])
for rm in reversed(to_remove):
del structure[rm[0]][rm[1]][rm[2]]
options = gemmi.cif.WriteOptions()
options.misuse_hash = True
options.align_pairs = 48
options.align_loops = 20
structure.make_mmcif_document().write_file(str(output_path), options)Looking through the documentation and issues (#60 (comment)), I found it is possible to load the file as a def write_doc(input_structure: Path, output_path: Path) -> None:
structure = gemmi.read_structure(str(input_structure))
structure.setup_entities()
to_remove = []
for model_idx, model in enumerate(structure):
for chain_idx, chain in enumerate(model):
for residue_idx, residue in enumerate(chain):
# simplified example of removing residues/atoms
# in my code I filter by altloc value on the level of atoms
if residue.name == "GLC":
to_remove.append([model_idx,chain_idx,residue_idx])
for rm in reversed(to_remove):
del structure[rm[0]][rm[1]][rm[2]]
groups = gemmi.MmcifOutputGroups(True)
groups.atoms = True
doc = gemmi.cif.read(str(input_structure))
# block = doc.find_block(structure.info["_entry.id"])
block = doc.sole_block()
structure.update_mmcif_block(block, groups)
options = gemmi.cif.WriteOptions()
options.misuse_hash = True
options.align_pairs = 48
options.align_loops = 20
doc.write_file(str(output_path), options)I would expect, that setting
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
There was a somewhat related question last month: #362 |
Beta Was this translation helpful? Give feedback.
There was a somewhat related question last month: #362