Skip to content

Commit

Permalink
Do not produce flawed PDB files (cases where model does not fit into …
Browse files Browse the repository at this point in the history
…PDB format). Adjust tests.
  • Loading branch information
olegsobolev committed Nov 6, 2023
1 parent 49645c2 commit 6b0652b
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 30 deletions.
2 changes: 2 additions & 0 deletions iotbx/pdb/hierarchy.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,8 @@ def as_pdb_string(self,
:param siguij: write SIGUIJ records if applicable
:returns: Python str
"""
if not self.fits_in_pdb_format():
return ""
if (cstringio is None):
cstringio = StringIO()
if (return_cstringio is Auto):
Expand Down
9 changes: 5 additions & 4 deletions iotbx/regression/tst_hierarchy_long_chain_ids_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,10 +261,11 @@ def test1():
# Note here incorrect/trimmed chain id
# There's no way to correctly output chain ids longer than 2 char in PDB format
print(o_pdb_str)
assert_lines_in_text(o_pdb_str, """\
ATOM 61 C SERA-2 2 72.898 71.361 62.393 1.00 67.20 C
ATOM 62 O SERA-2 2 73.055 70.333 61.737 1.00 65.10 O
""")
assert o_pdb_str==""
# assert_lines_in_text(o_pdb_str, """\
# ATOM 61 C SERA-2 2 72.898 71.361 62.393 1.00 67.20 C
# ATOM 62 O SERA-2 2 73.055 70.333 61.737 1.00 65.10 O
# """)

o_cif_str = "%s" % h.as_cif_block()
assert_lines_in_text(o_cif_str, """\
Expand Down
17 changes: 9 additions & 8 deletions iotbx/regression/tst_hierarchy_long_resname_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ def test1():
# Note here incorrect/trimmed residue names
# There's no way to correctly output resnames longer than 3 char in PDB format
# print(o_pdb_str)
assert_lines_in_text(o_pdb_str, """\
ATOM 8 CE LYS A 279 -2.923 -13.799 42.993 1.00 52.86 C
ATOM 9 NZ LYS A 279 -3.209 -12.856 44.100 1.00 54.19 N
TER
HETATM 10 CA CA A 301 -17.362 -22.385 28.047 1.00 15.20 CA
HETATM 11 C10 7ZTVU A 302 -7.646 -6.965 5.796 1.00 22.62 C
HETATM 12 C2 7ZTVU A 302 -8.462 -5.534 9.265 1.00 16.68 C
""")
assert o_pdb_str == ""
# assert_lines_in_text(o_pdb_str, """\
# ATOM 8 CE LYS A 279 -2.923 -13.799 42.993 1.00 52.86 C
# ATOM 9 NZ LYS A 279 -3.209 -12.856 44.100 1.00 54.19 N
# TER
# HETATM 10 CA CA A 301 -17.362 -22.385 28.047 1.00 15.20 CA
# HETATM 11 C10 7ZTVU A 302 -7.646 -6.965 5.796 1.00 22.62 C
# HETATM 12 C2 7ZTVU A 302 -8.462 -5.534 9.265 1.00 16.68 C
# """)

o_cif_str = "%s" % h.as_cif_block()
# print(o_cif_str)
Expand Down
6 changes: 1 addition & 5 deletions iotbx/regression/tst_hierarchy_long_resname_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ def test1():
' HETATM 10 O . longHOH A 401 ? -3.20900 -12.85600 46.10000 1.000 30.11000 O ? B ? . 1']:
assert_lines_in_text(model_cif, l)
model_pdb = model.model_as_pdb()
# print(model_pdb)
for l in [
'LINK NZ LYS A 279 O longHOH A 401 ',
'HETATM 10 O longHOH A 401 -3.209 -12.856 46.100 1.00 30.11 O']:
assert_lines_in_text(model_pdb, l)
assert not model.can_be_outputted_as_pdb()

if (__name__ == "__main__"):
t0 = time.time()
Expand Down
7 changes: 1 addition & 6 deletions iotbx/regression/tst_hierarchy_long_resname_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,7 @@ def test1():
'data_comp_7ZTVU',
]:
assert_lines_in_text(model_cif, l)
model_pdb = model.model_as_pdb()
print(model_pdb)
for l in [
'HETATM 10 C10 7ZTVU A 302 -7.646 -6.965 5.796 1.00 22.62 C',
]:
assert_lines_in_text(model_pdb, l)
assert not model.can_be_outputted_as_pdb()

def test2():
"""
Expand Down
6 changes: 1 addition & 5 deletions iotbx/regression/tst_hierarchy_long_resname_4.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,7 @@ def test1():
assert_lines_in_text(model_cif, l)
model_pdb = model.model_as_pdb()
# print(model_pdb)
for l in [
'ATOM 20 ND2 ASN A 3 -1.271 0.715 7.306 1.00 13.48 N',
'ATOM 21 N longGLY A 4 -1.005 2.228 3.598 1.00 10.29 N',
]:
assert_lines_in_text(model_pdb, l)
assert not model.can_be_outputted_as_pdb()

def test2():
"""
Expand Down
2 changes: 1 addition & 1 deletion iotbx/regression/tst_hierarchy_pdb_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def test6():
for atom_group in residue_group.atom_groups():
for atom in atom_group.atoms():
atom.set_segid('UNK')
assert ph.as_pdb_string().find("UNK")>-1
# assert ph.as_pdb_string().find("UNK")>-1
assert ph.as_mmcif_string().find("UNK") == -1
assert ph.as_mmcif_string(segid_as_auth_segid=True).find("UNK") > -1

Expand Down
2 changes: 1 addition & 1 deletion mmtbx/model/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ def _figure_out_hierarchy_to_output(self, do_not_shift_back):
return hierarchy_to_output

def can_be_outputted_as_pdb(self):
return True
return self.get_hierarchy().fits_in_pdb_format()

def model_as_pdb(self,
output_cs = True,
Expand Down

0 comments on commit 6b0652b

Please sign in to comment.