From c638290de2a113481d97537610035905a1e7e07b Mon Sep 17 00:00:00 2001
From: James Graham <J.A.Graham@soton.ac.uk>
Date: Tue, 11 Apr 2017 15:45:20 +0100
Subject: [PATCH] Make certain parameters to __init__ functions required where
 this makes sense

---
 pycgtool/bondset.py |  8 ++++----
 pycgtool/frame.py   | 12 +++++++++++-
 pycgtool/mapping.py | 26 +++++++++++++-------------
 test/test_frame.py  |  6 +++---
 4 files changed, 31 insertions(+), 21 deletions(-)

diff --git a/pycgtool/bondset.py b/pycgtool/bondset.py
index 972e053..0ce9e97 100644
--- a/pycgtool/bondset.py
+++ b/pycgtool/bondset.py
@@ -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
diff --git a/pycgtool/frame.py b/pycgtool/frame.py
index b61d6c8..d8877a9 100644
--- a/pycgtool/frame.py
+++ b/pycgtool/frame.py
@@ -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
diff --git a/pycgtool/mapping.py b/pycgtool/mapping.py
index e566c45..437103e 100644
--- a/pycgtool/mapping.py
+++ b/pycgtool/mapping.py
@@ -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),
@@ -92,7 +92,7 @@ class Mapping:
                 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
@@ -101,7 +101,7 @@ class Mapping:
                     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
@@ -202,7 +202,7 @@ class Mapping:
                 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
diff --git a/test/test_frame.py b/test/test_frame.py
index 4e95882..cd6a01f 100644
--- a/test/test_frame.py
+++ b/test/test_frame.py
@@ -22,13 +22,13 @@ class AtomTest(unittest.TestCase):
         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)
 
-- 
GitLab