Skip to content

Commit

Permalink
Add resolution saving
Browse files Browse the repository at this point in the history
  • Loading branch information
samirelanduk committed Oct 26, 2017
1 parent 50de3e3 commit 3e1afdf
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 8 deletions.
3 changes: 2 additions & 1 deletion atomium/files/pdb2pdbdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def pdb_to_pdb_dict(pdb):
pdb_dict["deposition_date"] = pdb._deposition_date
pdb_dict["code"] = pdb._code
pdb_dict["title"] = pdb._title
pdb_dict["resolution"] = pdb._resolution
return pdb_dict


Expand All @@ -38,7 +39,7 @@ def structure_to_pdb_dict(structure):
connections = structure_to_connections(structure)
return {
"models": [model], "connections": connections,
"deposition_date": None, "code": None, "title": None
"deposition_date": None, "code": None, "title": None, "resolution": None
}


Expand Down
8 changes: 8 additions & 0 deletions atomium/files/pdbdict2pdbstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ def pack_header(lines, pdb_dict):
chunk
).ljust(80) for number, chunk in enumerate(title_chunks, start=1)]
lines += title_records
if pdb_dict["resolution"] is not None:
lines.append("REMARK 2".ljust(80))
if pdb_dict["resolution"] == 0:
lines.append("REMARK 2 RESOLUTION. NOT APPLICABLE.".ljust(80))
else:
lines.append("REMARK 2 RESOLUTION. {:.2f} ANGSTROMS.".format(
pdb_dict["resolution"]
).ljust(80))


def pack_structure(lines, pdb_dict):
Expand Down
2 changes: 1 addition & 1 deletion atomium/files/pdbstring2pdbdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def extract_header(pdb_dict, lines):
if int(remark[7:10]) == 2 and remark[10:].strip():
try:
pdb_dict["resolution"] = float(remark[10:].strip().split()[1])
except ValueError: pdb_dict["resolution"] = None
except ValueError: pdb_dict["resolution"] = 0
break
else:
pdb_dict["resolution"] = None
Expand Down
1 change: 1 addition & 0 deletions tests/integration/files/1cbn_output.pdb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
HEADER 11-OCT-91 1CBN
TITLE ATOMIC RESOLUTION (0.83 ANGSTROMS) CRYSTAL STRUCTURE OF THE HYDROPHOBI
TITLE 2 C PROTEIN CRAMBIN AT 130 K
REMARK 2
REMARK 2 RESOLUTION. 0.83 ANGSTROMS.
ATOM 1 N THR A 1 16.864 14.059 3.442 1.00 6.22 N
ATOM 3 CA THR A 1 16.868 12.814 4.233 1.00 4.45 C
Expand Down
1 change: 1 addition & 0 deletions tests/integration/files/1lol_output.pdb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
HEADER 06-MAY-02 1LOL
TITLE CRYSTAL STRUCTURE OF OROTIDINE MONOPHOSPHATE DECARBOXYLASE COMPLEX WIT
TITLE 2 H XMP
REMARK 2
REMARK 2 RESOLUTION. 1.90 ANGSTROMS.
ATOM 1 N VAL A 11 3.696 33.898 63.219 1.00 21.5 N
ATOM 2 CA VAL A 11 3.198 33.218 61.983 1.00 19.76 C
Expand Down
1 change: 1 addition & 0 deletions tests/integration/files/5xme_output.pdb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
HEADER 15-MAY-17 5XME
TITLE SOLUTION STRUCTURE OF C-TERMINAL DOMAIN OF TRADD
REMARK 2
REMARK 2 RESOLUTION. NOT APPLICABLE.
MODEL 1
ATOM 1 N ALA A 199 33.969 -8.430 -0.271 1.00 N
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_can_read_pdb(self):

def test_can_read_multi_model_pdbs(self):
pdb = atomium.pdb_from_file("tests/integration/files/5xme.pdb")
self.assertEqual(pdb.resolution(), None)
self.assertEqual(pdb.resolution(), 0)

models = pdb.models()
self.assertEqual(len(models), 10)
Expand Down
26 changes: 24 additions & 2 deletions tests/unit/files_tests/test_pdb_dict_to_pdb_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class HeaderPackingTests(TestCase):
def setUp(self):
self.pdb_dict = {
"deposition_date": datetime(1990, 9, 1).date(),
"code": "1XYZ", "title": "ABC" * 40
"code": "1XYZ", "title": "ABC" * 40, "resolution": 1.9
}
self.lines = []

Expand All @@ -34,12 +34,15 @@ def test_can_pack_full_header(self):
self.assertEqual(self.lines, [
"HEADER" + " " * 44 + "01-SEP-90 1XYZ" + " " * 14,
"TITLE " + "ABC" * 23 + "A",
"TITLE 2 " + "BC" + "ABC" * 16 + " " * 19
"TITLE 2 " + "BC" + "ABC" * 16 + " " * 19,
"REMARK 2" + " " * 70,
"REMARK 2 RESOLUTION. 1.90 ANGSTROMS.".ljust(80)
])


def test_can_pack_deposition_date(self):
self.pdb_dict["code"], self.pdb_dict["title"] = None, None
self.pdb_dict["resolution"] = None
pack_header(self.lines, self.pdb_dict)
self.assertEqual(self.lines, [
"HEADER" + " " * 44 + "01-SEP-90 " + " " * 14,
Expand All @@ -48,6 +51,7 @@ def test_can_pack_deposition_date(self):

def test_can_pack_code(self):
self.pdb_dict["deposition_date"], self.pdb_dict["title"] = None, None
self.pdb_dict["resolution"] = None
pack_header(self.lines, self.pdb_dict)
self.assertEqual(self.lines, [
"HEADER" + " " * 44 + " 1XYZ" + " " * 14,
Expand All @@ -56,13 +60,31 @@ def test_can_pack_code(self):

def test_can_pack_title(self):
self.pdb_dict["deposition_date"], self.pdb_dict["code"] = None, None
self.pdb_dict["resolution"] = None
pack_header(self.lines, self.pdb_dict)
self.assertEqual(self.lines, [
"TITLE " + "ABC" * 23 + "A",
"TITLE 2 " + "BC" + "ABC" * 16 + " " * 19
])


def test_can_pack_resolution(self):
self.pdb_dict["deposition_date"], self.pdb_dict["title"] = None, None
self.pdb_dict["code"] = None
pack_header(self.lines, self.pdb_dict)
self.assertEqual(self.lines[0], "REMARK 2" + " " * 70)
self.assertEqual(self.lines[1], "REMARK 2 RESOLUTION. 1.90 ANGSTROMS.".ljust(80))


def test_can_pack_zero_resolution(self):
self.pdb_dict["deposition_date"], self.pdb_dict["title"] = None, None
self.pdb_dict["code"] = None
self.pdb_dict["resolution"] = 0
pack_header(self.lines, self.pdb_dict)
self.assertEqual(self.lines[0], "REMARK 2" + " " * 70)
self.assertEqual(self.lines[1], "REMARK 2 RESOLUTION. NOT APPLICABLE.".ljust(80))



class StructurePackingTests(TestCase):

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/files_tests/test_pdb_string_to_pdb_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_empty_remark_extraction(self, mock_lines, mock_line):
extract_header(self.pdb_dict, self.lines)
mock_lines.assert_any_call("TITLE", self.lines)
mock_lines.assert_any_call("REMARK", self.lines)
self.assertEqual(self.pdb_dict["resolution"], None)
self.assertEqual(self.pdb_dict["resolution"], 0)


@patch("atomium.files.pdbstring2pdbdict.get_line")
Expand Down
7 changes: 5 additions & 2 deletions tests/unit/files_tests/test_pdb_to_pdb_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ def test_can_convert_pdb_to_pdb_dict_one_model(self, mock_dict):
pdb._deposition_date = "D"
pdb._code = "C"
pdb._title = "T"
pdb._resolution = 1.5
pdb._models = ["model1"]
mock_dict.return_value = {"models": ["m1"], "connections": ["c1", "c2"]}
pdb_dict = pdb_to_pdb_dict(pdb)
mock_dict.assert_called_with("model1")
self.assertEqual(pdb_dict, {
"deposition_date": "D", "code": "C", "title": "T",
"deposition_date": "D", "code": "C", "title": "T", "resolution": 1.5,
"models": ["m1"], "connections": ["c1", "c2"]
})

Expand All @@ -26,6 +27,7 @@ def test_can_convert_pdb_to_pdb_dict_two_models(self, mock_dict):
pdb._deposition_date = "D"
pdb._code = "C"
pdb._title = "T"
pdb._resolution = 1.5
pdb._models = ["model1", "model2"]
mock_dict.side_effect = [
{"models": ["m1"], "connections": ["c1", "c2"]},
Expand All @@ -35,7 +37,7 @@ def test_can_convert_pdb_to_pdb_dict_two_models(self, mock_dict):
mock_dict.assert_any_call("model1")
mock_dict.assert_any_call("model2")
self.assertEqual(pdb_dict, {
"deposition_date": "D", "code": "C", "title": "T",
"deposition_date": "D", "code": "C", "title": "T", "resolution": 1.5,
"models": ["m1", "m2"], "connections": ["c1", "c2"]
})

Expand Down Expand Up @@ -69,6 +71,7 @@ def test_can_convert_model_to_pdb_dict(self, mock_con, mock_res, mock_chain, moc
"deposition_date": None,
"code": None,
"title": None,
"resolution": None,
"models": [{
"chains": ["chain1", "chain2"],
"molecules": ["mol1", "mol2"]
Expand Down

0 comments on commit 3e1afdf

Please sign in to comment.