Skip to content

Commit

Permalink
Replace is_numeric with isinstance to speed up parse
Browse files Browse the repository at this point in the history
  • Loading branch information
samirelanduk committed Oct 26, 2017
1 parent b681eb6 commit 6ab22fe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
22 changes: 11 additions & 11 deletions atomium/structures/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import weakref
from math import sqrt, acos, degrees
from points import Vector, is_numeric
from points import Vector

class Atom:
"""Represents an atom in three dimensional space. Every atom has an element
Expand Down Expand Up @@ -31,19 +31,19 @@ def __init__(self, element, x, y, z, atom_id=None, name=None, charge=0,
raise TypeError("Element '{}' is not str".format(element))
if not 0 < len(element) < 3:
raise ValueError("Element {} is not 1 or 2 chars".format(element))
if not is_numeric(x):
if not isinstance(x, (float, int)):
raise TypeError("x coordinate '{}' is not numeric".format(x))
if not is_numeric(y):
if not isinstance(y, (float, int)):
raise TypeError("y coordinate '{}' is not numeric".format(y))
if not is_numeric(z):
if not isinstance(z, (float, int)):
raise TypeError("z coordinate '{}' is not numeric".format(z))
if atom_id is not None and not isinstance(atom_id, int):
raise TypeError("ID {} is not an integer".format(atom_id))
if name is not None and not isinstance(name, str):
raise TypeError("name {} is not a string".format(name))
if not is_numeric(charge):
if not isinstance(charge, (float, int)):
raise TypeError("charge '{}' is not numeric".format(charge))
if not is_numeric(bfactor):
if not isinstance(bfactor, (float, int)):
raise TypeError("bfactor '{}' is not numeric".format(bfactor))
self._element = element
self._x = x
Expand Down Expand Up @@ -96,7 +96,7 @@ def x(self, x=None):
if x is None:
return self._x
else:
if not is_numeric(x):
if not isinstance(x, (float, int)):
raise TypeError("x coordinate '{}' is not numeric".format(x))
self._x = x

Expand All @@ -112,7 +112,7 @@ def y(self, y=None):
if y is None:
return self._y
else:
if not is_numeric(y):
if not isinstance(y, (float, int)):
raise TypeError("y coordinate '{}' is not numeric".format(y))
self._y = y

Expand All @@ -128,7 +128,7 @@ def z(self, z=None):
if z is None:
return self._z
else:
if not is_numeric(z):
if not isinstance(z, (float, int)):
raise TypeError("z coordinate '{}' is not numeric".format(z))
self._z = z

Expand Down Expand Up @@ -211,7 +211,7 @@ def charge(self, charge=None):
if charge is None:
return self._charge
else:
if not is_numeric(charge):
if not isinstance(charge, (float, int)):
raise TypeError("charge '{}' is not numeric".format(charge))
self._charge = charge

Expand All @@ -227,7 +227,7 @@ def bfactor(self, bfactor=None):
if bfactor is None:
return self._bfactor
else:
if not is_numeric(bfactor):
if not isinstance(bfactor, (float, int)):
raise TypeError("bfactor '{}' is not numeric".format(bfactor))
self._bfactor = bfactor

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/structure_tests/test_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def setUp(self):
self.mock_residues = self.patcher2.start()
self.mock_residues.return_value = (self.residue1, self.residue2)
def mock_init(obj, *args, **kwargs):
obj._atoms = set()
obj._id_atoms = {}
obj._atoms = set(args[:1])
obj._id_atoms = {i: arg for i, arg in enumerate(args[1:])}
self.mock_init = mock_init


Expand Down
4 changes: 2 additions & 2 deletions tests/unit/structure_tests/test_molecules.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def setUp(self):
self.atom1, self.atom2, self.atom3 = Mock(Atom), Mock(Atom), Mock(Atom)
self.atoms = [self.atom1, self.atom2, self.atom3]
def mock_init(obj, *args, **kwargs):
obj._atoms = set()
obj._id_atoms = {}
obj._atoms = set(args[:1])
obj._id_atoms = {i: arg for i, arg in enumerate(args[1:])}
self.mock_init = mock_init


Expand Down
4 changes: 2 additions & 2 deletions tests/unit/structure_tests/test_residues.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ def setUp(self):
for index, atom in enumerate(self.atoms, start=1):
atom.atom_id.return_value = index
def mock_init(obj, *args, **kwargs):
obj._atoms = set()
obj._id_atoms = {}
obj._atoms = set(args[:1])
obj._id_atoms = {i: arg for i, arg in enumerate(args[1:])}
self.mock_init = mock_init


Expand Down

0 comments on commit 6ab22fe

Please sign in to comment.