Skip to content

Commit

Permalink
Make certain parameters to __init__ functions required where this mak…
Browse files Browse the repository at this point in the history
…es sense
  • Loading branch information
jag1g13 committed Apr 11, 2017
1 parent 52f2355 commit c638290
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
8 changes: 4 additions & 4 deletions pycgtool/bondset.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class Bond:
"""
__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.
:param atoms: List of atom names defining the bond
:param atom_numbers: List of atom numbers defining the bond
:return: Instance of Bond
:param List[str] atoms: List of atom names defining the bond
:param List[int] atom_numbers: List of atom numbers defining the bond
:param func_form: Functional form to use for Boltzmann Inversion
"""
self.atoms = atoms
self.atom_numbers = atom_numbers
Expand Down
12 changes: 11 additions & 1 deletion pycgtool/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ class Atom:
"""
__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.num = num
self.type = type
Expand Down
26 changes: 13 additions & 13 deletions pycgtool/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ class BeadMap(Atom):
"""
__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
:param name: The name of the bead
:param type: The bead type
:param atoms: The atom names from which the bead is made up
:param charge: The net charge on the bead
:param mass: The total bead mass
:return: Instance of BeadMap
Create a single bead mapping.
:param str name: The name of the bead
:param int num: The number of the bead
:param str type: The bead type
:param List[str] atoms: The atom names from which the bead is made up
:param float charge: The net charge on the bead
: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
# 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),
Expand Down Expand Up @@ -92,7 +92,7 @@ def __init__(self, filename, options, itp=None):
self._mappings[mol_name] = []
self._manual_charges[mol_name] = False
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
try:
# Allow optional charge in mapping file
Expand All @@ -101,7 +101,7 @@ def __init__(self, filename, options, itp=None):
except ValueError:
atoms.insert(0, first)
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)

# TODO this only works with one moleculetype in one itp - extend this
Expand Down Expand Up @@ -202,7 +202,7 @@ def _cg_frame_setup(self, aa_residues, name=None):
continue

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)):
cgres.name_to_num[bead.name] = i
Expand Down
6 changes: 3 additions & 3 deletions test/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def test_atom_create(self):
self.assertEqual("Type", atom.type)

def test_atom_add_missing_data(self):
atom1 = Atom(name="Name", num=0, type="Type")
atom2 = Atom(mass=1)
atom1 = Atom("Name1", 0, type="Type")
atom2 = Atom("Name2", 0, mass=1)

with self.assertRaises(AssertionError):
atom1.add_missing_data(atom2)

atom2 = Atom(name="Name", num=0, mass=1)
atom2 = Atom("Name1", 0, mass=1)
atom1.add_missing_data(atom2)
self.assertEqual(1, atom1.mass)

Expand Down

0 comments on commit c638290

Please sign in to comment.