def test_residue(self): res = gemmi.Residue() self.assertEqual(res.label_seq, None) self.assertEqual(res.seqid.num, None) res.label_seq = 1 self.assertEqual(res.label_seq, 1) res.seqid.num = 2 self.assertEqual(res.seqid.num, 2) res.label_seq = None self.assertEqual(res.label_seq, None) res.seqid.num = None self.assertEqual(res.seqid.num, None) for name in ['HOH', 'hoh', 'DOD', 'h2o', 'H2O', 'WAT']: res.name = name self.assertTrue(res.is_water()) for name in ['SO4', '', 'HO', 'hoho', 'oho']: res.name = name self.assertFalse(res.is_water())
def test_model_all(self): model = gemmi.Model('1') for name in 'ABCDEFG': model.add_chain(gemmi.Chain(name)) expected = [] for cname in 'BCF': chain = model[cname] for _ in range(7): chain.add_residue(gemmi.Residue()) for (r, name) in [(2, '0'), (2, '1'), (3, '2'), (5, '3')]: a = gemmi.Atom() a.name = cname + name expected.append(a.name) chain[r].add_atom(a) self.assertEqual([cra.atom.name for cra in model.all()], expected) st = gemmi.Structure() st.add_model(model) st.remove_empty_chains() self.assertEqual([cra.atom.name for cra in model.all()], expected)
def get_masked_pdb(pdb: gemmi.Structure, coord: Coord, radius: float = 8.0) -> gemmi.Structure: event_centoid = gemmi.Position( coord.x, coord.y, coord.z, ) new_structure = gemmi.Structure() for model_i, model in enumerate(pdb): new_model = gemmi.Model(model.name) new_structure.add_model(new_model, pos=-1) for chain_i, chain in enumerate(model): new_chain = gemmi.Chain(chain.name) new_structure[model_i].add_chain(new_chain, pos=-1) for residue_i, residue in enumerate(chain): new_residue = gemmi.Residue() new_residue.name = residue.name new_residue.seqid = residue.seqid new_residue.subchain = residue.subchain new_residue.label_seq = residue.label_seq new_residue.het_flag = residue.het_flag new_structure[model_i][chain_i].add_residue(new_residue, pos=-1) for atom_i, atom in enumerate(residue): pos = atom.pos if pos.dist(event_centoid) > radius: new_structure[model_i][chain_i][residue_i].add_atom( atom, pos=-1) for model_i, model in enumerate(pdb): pdb.add_model(new_structure[model_i], pos=-1) del pdb[0] return pdb