Skip to content
Snippets Groups Projects
Commit c638290d authored by James Graham's avatar James Graham
Browse files

Make certain parameters to __init__ functions required where this makes sense

parent 52f23554
No related branches found
No related tags found
No related merge requests found
...@@ -33,13 +33,13 @@ class Bond: ...@@ -33,13 +33,13 @@ class Bond:
""" """
__slots__ = ["atoms", "atom_numbers", "values", "eqm", "fconst", "_func_form"] __slots__ = ["atoms", "atom_numbers", "values", "eqm", "fconst", "_func_form"]
def __init__(self, atoms=None, atom_numbers=None, func_form=None): def __init__(self, atoms, atom_numbers=None, func_form=None):
""" """
Create a single bond definition. Create a single bond definition.
:param atoms: List of atom names defining the bond :param List[str] atoms: List of atom names defining the bond
:param atom_numbers: List of atom numbers defining the bond :param List[int] atom_numbers: List of atom numbers defining the bond
:return: Instance of Bond :param func_form: Functional form to use for Boltzmann Inversion
""" """
self.atoms = atoms self.atoms = atoms
self.atom_numbers = atom_numbers self.atom_numbers = atom_numbers
......
...@@ -37,7 +37,17 @@ class Atom: ...@@ -37,7 +37,17 @@ class Atom:
""" """
__slots__ = ["name", "num", "type", "mass", "charge", "coords"] __slots__ = ["name", "num", "type", "mass", "charge", "coords"]
def __init__(self, name=None, num=None, type=None, mass=None, charge=None, coords=None): def __init__(self, name, num, type=None, mass=None, charge=None, coords=None):
"""
Create an atom.
:param str name: The name of the atom
:param int num: The atom number
:param str type: The atom type
:param float mass: The mass of the atom
:param float charge: The charge of the atom
:param coords: The coordinates of the atom
"""
self.name = name self.name = name
self.num = num self.num = num
self.type = type self.type = type
......
...@@ -29,18 +29,18 @@ class BeadMap(Atom): ...@@ -29,18 +29,18 @@ class BeadMap(Atom):
""" """
__slots__ = ["name", "type", "atoms", "charge", "mass", "weights", "weights_dict"] __slots__ = ["name", "type", "atoms", "charge", "mass", "weights", "weights_dict"]
def __init__(self, name=None, type=None, atoms=None, charge=0, mass=0): def __init__(self, name, num, type=None, atoms=None, charge=0, mass=0):
""" """
Create a single bead mapping Create a single bead mapping.
:param name: The name of the bead :param str name: The name of the bead
:param type: The bead type :param int num: The number of the bead
:param atoms: The atom names from which the bead is made up :param str type: The bead type
:param charge: The net charge on the bead :param List[str] atoms: The atom names from which the bead is made up
:param mass: The total bead mass :param float charge: The net charge on the bead
:return: Instance of BeadMap :param float mass: The total bead mass
""" """
Atom.__init__(self, name=name, type=type, charge=charge, mass=mass) Atom.__init__(self, name, num, type=type, charge=charge, mass=mass)
self.atoms = atoms self.atoms = atoms
# NB: Mass weights are added in Mapping.__init__ if an itp file is provided # NB: Mass weights are added in Mapping.__init__ if an itp file is provided
self.weights_dict = {"geom": np.array([[1. / len(atoms)] for _ in atoms], dtype=np.float32), self.weights_dict = {"geom": np.array([[1. / len(atoms)] for _ in atoms], dtype=np.float32),
...@@ -92,7 +92,7 @@ class Mapping: ...@@ -92,7 +92,7 @@ class Mapping:
self._mappings[mol_name] = [] self._mappings[mol_name] = []
self._manual_charges[mol_name] = False self._manual_charges[mol_name] = False
molmap = self._mappings[mol_name] molmap = self._mappings[mol_name]
for name, typ, first, *atoms in mol_section: for i, (name, typ, first, *atoms) in enumerate(mol_section):
charge = 0 charge = 0
try: try:
# Allow optional charge in mapping file # Allow optional charge in mapping file
...@@ -101,7 +101,7 @@ class Mapping: ...@@ -101,7 +101,7 @@ class Mapping:
except ValueError: except ValueError:
atoms.insert(0, first) atoms.insert(0, first)
assert atoms, "Bead {0} specification contains no atoms".format(name) assert atoms, "Bead {0} specification contains no atoms".format(name)
newbead = BeadMap(name=name, type=typ, atoms=atoms, charge=charge) newbead = BeadMap(name, i, type=typ, atoms=atoms, charge=charge)
molmap.append(newbead) molmap.append(newbead)
# TODO this only works with one moleculetype in one itp - extend this # TODO this only works with one moleculetype in one itp - extend this
...@@ -202,7 +202,7 @@ class Mapping: ...@@ -202,7 +202,7 @@ class Mapping:
continue continue
cgres = Residue(name=aares.name, num=aares.num) cgres = Residue(name=aares.name, num=aares.num)
cgres.atoms = [Atom(name=bmap.name, type=bmap.type, charge=bmap.charge, mass=bmap.mass, coords=np.zeros(3)) for bmap in molmap] cgres.atoms = [Atom(bmap.name, bmap.num, type=bmap.type, charge=bmap.charge, mass=bmap.mass, coords=np.zeros(3)) for bmap in molmap]
for i, (bead, bmap) in enumerate(zip(cgres, molmap)): for i, (bead, bmap) in enumerate(zip(cgres, molmap)):
cgres.name_to_num[bead.name] = i cgres.name_to_num[bead.name] = i
......
...@@ -22,13 +22,13 @@ class AtomTest(unittest.TestCase): ...@@ -22,13 +22,13 @@ class AtomTest(unittest.TestCase):
self.assertEqual("Type", atom.type) self.assertEqual("Type", atom.type)
def test_atom_add_missing_data(self): def test_atom_add_missing_data(self):
atom1 = Atom(name="Name", num=0, type="Type") atom1 = Atom("Name1", 0, type="Type")
atom2 = Atom(mass=1) atom2 = Atom("Name2", 0, mass=1)
with self.assertRaises(AssertionError): with self.assertRaises(AssertionError):
atom1.add_missing_data(atom2) atom1.add_missing_data(atom2)
atom2 = Atom(name="Name", num=0, mass=1) atom2 = Atom("Name1", 0, mass=1)
atom1.add_missing_data(atom2) atom1.add_missing_data(atom2)
self.assertEqual(1, atom1.mass) self.assertEqual(1, atom1.mass)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment