Skip to content

Commit

Permalink
Add saving of rfactor in PDBs
Browse files Browse the repository at this point in the history
  • Loading branch information
samirelanduk committed Nov 16, 2017
1 parent 1b06003 commit 29aa399
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
3 changes: 2 additions & 1 deletion atomium/files/pdb2pdbdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def pdb_to_pdb_dict(pdb):
pdb_dict["code"] = pdb._code
pdb_dict["title"] = pdb._title
pdb_dict["resolution"] = pdb._resolution
pdb_dict["rfactor"] = pdb._rfactor
pdb_dict["organism"] = pdb._organism
pdb_dict["expression_system"] = pdb._expression_system
pdb_dict["technique"] = pdb._technique
Expand Down Expand Up @@ -45,7 +46,7 @@ def structure_to_pdb_dict(structure):
"models": [model], "connections": connections,
"deposition_date": None, "code": None, "title": None, "resolution": None,
"organism": None, "expression_system": None, "technique": None,
"classification": None
"classification": None, "rfactor": None
}


Expand Down
14 changes: 14 additions & 0 deletions atomium/files/pdbdict2pdbstring.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def pack_annotation(lines, pdb_dict):
pack_source(lines, pdb_dict)
pack_technique(lines, pdb_dict)
pack_resolution(lines, pdb_dict)
pack_rfactor(lines, pdb_dict)


def pack_header(lines, pdb_dict):
Expand Down Expand Up @@ -82,6 +83,19 @@ def pack_resolution(lines, pdb_dict):
).ljust(80))


def pack_rfactor(lines, pdb_dict):
"""Adds REMARK records to a list of lines for rfactor.
:param list lines: The record lines to add to.
:param dict pdb_dict: The data dictionary to pack."""

if pdb_dict["rfactor"] is not None:
lines.append("REMARK 3".ljust(80))
lines.append("REMARK 3 R VALUE (WORKING SET) : {}".format(
pdb_dict["rfactor"]
).ljust(80))


def pack_source(lines, pdb_dict):
"""Adds SOURCE records to a list of lines for source organism and
expression system.
Expand Down
2 changes: 2 additions & 0 deletions tests/integration/files/1lol_output.pdb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ SOURCE 2 EXPRESSION_SYSTEM: COOL NEW ORGANISM;
EXPDTA MEME DIFFRACTION
REMARK 2
REMARK 2 RESOLUTION. 1.90 ANGSTROMS.
REMARK 3
REMARK 3 R VALUE (WORKING SET) : 0.193
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
ATOM 3 C VAL A 11 3.914 31.863 61.818 1.00 19.29 C
Expand Down
25 changes: 22 additions & 3 deletions tests/unit/files_tests/test_pdb_dict_to_pdb_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def setUp(self):
self.pdb_dict = {
"deposition_date": datetime(1990, 9, 1).date(),
"code": "1XYZ", "title": "ABC" * 40, "resolution": 1.9,
"technique": "TECH", "classification": "CLASS",
"technique": "TECH", "classification": "CLASS", "rfactor": 3.4,
"organism": "HOMO SAPIENS", "expression_system": "MUS MUSCULUS"
}
self.lines = []
Expand Down Expand Up @@ -37,13 +37,15 @@ class AnnotationPackingTests(PdbStringCreationTest):
@patch("atomium.files.pdbdict2pdbstring.pack_header")
@patch("atomium.files.pdbdict2pdbstring.pack_title")
@patch("atomium.files.pdbdict2pdbstring.pack_resolution")
@patch("atomium.files.pdbdict2pdbstring.pack_rfactor")
@patch("atomium.files.pdbdict2pdbstring.pack_source")
@patch("atomium.files.pdbdict2pdbstring.pack_technique")
def test_can_pack_annotation(self, mock_tech, mock_source, mock_res, mock_title, mock_head):
def test_can_pack_annotation(self, mock_tech, mock_source, mock_rfac, mock_res, mock_title, mock_head):
pack_annotation(self.lines, self.pdb_dict)
mock_head.assert_called_with(self.lines, self.pdb_dict)
mock_title.assert_called_with(self.lines, self.pdb_dict)
mock_res.assert_called_with(self.lines, self.pdb_dict)
mock_rfac.assert_called_with(self.lines, self.pdb_dict)
mock_source.assert_called_with(self.lines, self.pdb_dict)
mock_tech.assert_called_with(self.lines, self.pdb_dict)

Expand Down Expand Up @@ -120,6 +122,23 @@ def test_can_pack_zero_resolution(self):



class RfactorPackingTests(PdbStringCreationTest):

def test_can_pack_resolution(self):
pack_rfactor(self.lines, self.pdb_dict)
self.assertEqual(self.lines[0], "REMARK 3" + " " * 70)
self.assertEqual(
self.lines[1], "REMARK 3 R VALUE (WORKING SET) : 3.4".ljust(80)
)


def test_can_pack_no_rfactor(self):
self.pdb_dict["resolution"] = None
pack_resolution(self.lines, self.pdb_dict)
self.assertEqual(self.lines, [])



class SourcePackingTests(PdbStringCreationTest):

def test_can_pack_source(self):
Expand Down Expand Up @@ -150,7 +169,7 @@ def test_can_pack_nothing(self):
self.pdb_dict["technique"] = None
pack_technique(self.lines, self.pdb_dict)
self.assertEqual(self.lines, [])



class StructurePackingTests(TestCase):
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 @@ -11,6 +11,7 @@ def test_can_convert_pdb_to_pdb_dict_one_model(self, mock_dict):
pdb._code = "C"
pdb._title = "T"
pdb._resolution = 1.5
pdb._rfactor = 1.8
pdb._organism = "O"
pdb._expression_system = "E"
pdb._technique = "T"
Expand All @@ -22,7 +23,7 @@ def test_can_convert_pdb_to_pdb_dict_one_model(self, mock_dict):
self.assertEqual(pdb_dict, {
"deposition_date": "D", "code": "C", "title": "T", "resolution": 1.5,
"organism": "O", "expression_system": "E", "technique": "T",
"classification": "CLASS",
"classification": "CLASS", "rfactor": 1.8,
"models": ["m1"], "connections": ["c1", "c2"]
})

Expand All @@ -34,6 +35,7 @@ def test_can_convert_pdb_to_pdb_dict_two_models(self, mock_dict):
pdb._code = "C"
pdb._title = "T"
pdb._resolution = 1.5
pdb._rfactor = 1.8
pdb._organism = "O"
pdb._expression_system = "E"
pdb._technique = "T"
Expand All @@ -49,7 +51,7 @@ def test_can_convert_pdb_to_pdb_dict_two_models(self, mock_dict):
self.assertEqual(pdb_dict, {
"deposition_date": "D", "code": "C", "title": "T", "resolution": 1.5,
"organism": "O", "expression_system": "E", "technique": "T",
"classification": "CLASS",
"classification": "CLASS", "rfactor": 1.8,
"models": ["m1", "m2"], "connections": ["c1", "c2"]
})

Expand Down Expand Up @@ -84,6 +86,7 @@ def test_can_convert_model_to_pdb_dict(self, mock_con, mock_res, mock_chain, moc
"code": None,
"title": None,
"resolution": None,
"rfactor": None,
"organism": None,
"expression_system": None,
"technique": None,
Expand Down

0 comments on commit 29aa399

Please sign in to comment.