Skip to content

Commit c638290

Browse files
committed
Make certain parameters to __init__ functions required where this makes sense
1 parent 52f2355 commit c638290

File tree

4 files changed

+31
-21
lines changed

4 files changed

+31
-21
lines changed

pycgtool/bondset.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ class Bond:
3333
"""
3434
__slots__ = ["atoms", "atom_numbers", "values", "eqm", "fconst", "_func_form"]
3535

36-
def __init__(self, atoms=None, atom_numbers=None, func_form=None):
36+
def __init__(self, atoms, atom_numbers=None, func_form=None):
3737
"""
3838
Create a single bond definition.
3939
40-
:param atoms: List of atom names defining the bond
41-
:param atom_numbers: List of atom numbers defining the bond
42-
:return: Instance of Bond
40+
:param List[str] atoms: List of atom names defining the bond
41+
:param List[int] atom_numbers: List of atom numbers defining the bond
42+
:param func_form: Functional form to use for Boltzmann Inversion
4343
"""
4444
self.atoms = atoms
4545
self.atom_numbers = atom_numbers

pycgtool/frame.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,17 @@ class Atom:
3737
"""
3838
__slots__ = ["name", "num", "type", "mass", "charge", "coords"]
3939

40-
def __init__(self, name=None, num=None, type=None, mass=None, charge=None, coords=None):
40+
def __init__(self, name, num, type=None, mass=None, charge=None, coords=None):
41+
"""
42+
Create an atom.
43+
44+
:param str name: The name of the atom
45+
:param int num: The atom number
46+
:param str type: The atom type
47+
:param float mass: The mass of the atom
48+
:param float charge: The charge of the atom
49+
:param coords: The coordinates of the atom
50+
"""
4151
self.name = name
4252
self.num = num
4353
self.type = type

pycgtool/mapping.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@ class BeadMap(Atom):
2929
"""
3030
__slots__ = ["name", "type", "atoms", "charge", "mass", "weights", "weights_dict"]
3131

32-
def __init__(self, name=None, type=None, atoms=None, charge=0, mass=0):
32+
def __init__(self, name, num, type=None, atoms=None, charge=0, mass=0):
3333
"""
34-
Create a single bead mapping
35-
36-
:param name: The name of the bead
37-
:param type: The bead type
38-
:param atoms: The atom names from which the bead is made up
39-
:param charge: The net charge on the bead
40-
:param mass: The total bead mass
41-
:return: Instance of BeadMap
34+
Create a single bead mapping.
35+
36+
:param str name: The name of the bead
37+
:param int num: The number of the bead
38+
:param str type: The bead type
39+
:param List[str] atoms: The atom names from which the bead is made up
40+
:param float charge: The net charge on the bead
41+
:param float mass: The total bead mass
4242
"""
43-
Atom.__init__(self, name=name, type=type, charge=charge, mass=mass)
43+
Atom.__init__(self, name, num, type=type, charge=charge, mass=mass)
4444
self.atoms = atoms
4545
# NB: Mass weights are added in Mapping.__init__ if an itp file is provided
4646
self.weights_dict = {"geom": np.array([[1. / len(atoms)] for _ in atoms], dtype=np.float32),
@@ -92,7 +92,7 @@ def __init__(self, filename, options, itp=None):
9292
self._mappings[mol_name] = []
9393
self._manual_charges[mol_name] = False
9494
molmap = self._mappings[mol_name]
95-
for name, typ, first, *atoms in mol_section:
95+
for i, (name, typ, first, *atoms) in enumerate(mol_section):
9696
charge = 0
9797
try:
9898
# Allow optional charge in mapping file
@@ -101,7 +101,7 @@ def __init__(self, filename, options, itp=None):
101101
except ValueError:
102102
atoms.insert(0, first)
103103
assert atoms, "Bead {0} specification contains no atoms".format(name)
104-
newbead = BeadMap(name=name, type=typ, atoms=atoms, charge=charge)
104+
newbead = BeadMap(name, i, type=typ, atoms=atoms, charge=charge)
105105
molmap.append(newbead)
106106

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

204204
cgres = Residue(name=aares.name, num=aares.num)
205-
cgres.atoms = [Atom(name=bmap.name, type=bmap.type, charge=bmap.charge, mass=bmap.mass, coords=np.zeros(3)) for bmap in molmap]
205+
cgres.atoms = [Atom(bmap.name, bmap.num, type=bmap.type, charge=bmap.charge, mass=bmap.mass, coords=np.zeros(3)) for bmap in molmap]
206206

207207
for i, (bead, bmap) in enumerate(zip(cgres, molmap)):
208208
cgres.name_to_num[bead.name] = i

test/test_frame.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ def test_atom_create(self):
2222
self.assertEqual("Type", atom.type)
2323

2424
def test_atom_add_missing_data(self):
25-
atom1 = Atom(name="Name", num=0, type="Type")
26-
atom2 = Atom(mass=1)
25+
atom1 = Atom("Name1", 0, type="Type")
26+
atom2 = Atom("Name2", 0, mass=1)
2727

2828
with self.assertRaises(AssertionError):
2929
atom1.add_missing_data(atom2)
3030

31-
atom2 = Atom(name="Name", num=0, mass=1)
31+
atom2 = Atom("Name1", 0, mass=1)
3232
atom1.add_missing_data(atom2)
3333
self.assertEqual(1, atom1.mass)
3434

0 commit comments

Comments
 (0)