Skip to content

Commit

Permalink
Add full residue names (resolves #12)
Browse files Browse the repository at this point in the history
  • Loading branch information
samirelanduk committed Jan 12, 2018
1 parent 07344d7 commit 3348915
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
16 changes: 14 additions & 2 deletions atomium/structures/molecules.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,15 +297,16 @@ def molecule_id(self, molecule_id=None):
return self._id


def name(self, name=None):
def name(self, name=None, full=False):
"""Returns the molecule's name. If a value is given, the name will be
updated, provided it is a string.
:param int name: If given, the name will be set to this.
:param bool full: If ``True`` the full English name will be returned.
:raises TypeError: if the name given is not str."""

if name is None:
return self._name
return RESIDUES.get(self._name, self._name) if full else self._name
else:
if not isinstance(name, str):
raise TypeError("Molecule name '{}' is not str".format(name))
Expand Down Expand Up @@ -489,3 +490,14 @@ def chain(self):

for atom in self.atoms():
return atom.chain()



RESIDUES = {
"GLY": "glycine", "ALA": "alanine", "VAL": "valine", "LEU": "leucine",
"ILE": "isoleucine", "MET": "methionine", "PHE": "phenylalanine",
"TRP": "tryptophan", "PRO": "proline", "SER": "serine", "THR": "threonine",
"CYS": "cysteine", "TYR": "tyrosine", "ASN": "asparagine", "GLN": "glutamine",
"ASP": "aspartic acid", "GLU": "glutamic acid", "LYS": "lysine",
"ARG": "arginine", "HIS": "histidine", "HOH": "water"
}
4 changes: 4 additions & 0 deletions tests/integration/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ def test_can_read_pdb(self):

# Residues are correct
self.assertEqual(chaina[0].name(), "VAL")
self.assertEqual(chaina[0].name(full=True), "valine")
self.assertEqual(chaina[0].next().name(), "MET")
self.assertEqual(chaina[0].next().name(full=True), "methionine")
self.assertEqual(chaina[-1].name(), "ILE")
self.assertEqual(chaina[-1].name(full=True), "isoleucine")
self.assertEqual(chaina[-1].previous().name(), "SER")
self.assertEqual(len(chaina.residues(name="ASN")), 6)
for residue in chaina:
Expand Down Expand Up @@ -77,6 +80,7 @@ def test_can_read_pdb(self):
mol = model.molecule(molecule_id="A2001")
self.assertIs(mol.model(), model)
self.assertEqual(mol.name(), "XMP")
self.assertEqual(mol.name(full=True), "XMP")
self.assertEqual(len(mol.atoms()), 24)

# Bindsites are correct
Expand Down
7 changes: 7 additions & 0 deletions tests/unit/structure_tests/test_molecules.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ def test_molecule_name_property(self):
self.assertIs(mol._name, mol.name())


def test_molecule_name_property_full(self):
mol = Molecule(self.atom1, self.atom2, self.atom3, name="VAL")
self.assertEqual(mol.name(full=True), "valine")
mol = Molecule(self.atom1, self.atom2, self.atom3, name="VL")
self.assertEqual(mol.name(full=True), "VL")


def test_can_update_molecule_name(self):
mol = Molecule(self.atom1, self.atom2, self.atom3, name="VAL")
mol.name("HIS")
Expand Down

0 comments on commit 3348915

Please sign in to comment.