From 7ceab4d89a647357db21510e595a26782fb57766 Mon Sep 17 00:00:00 2001
From: Parashara Shamaprasad
Date: Thu, 11 Apr 2019 11:40:33 -0500
Subject: [PATCH 01/14] Added dihedral and dihedral_type classes. Modified
topology to reflect changes
---
topology/core/dihedral.py | 54 ++++++++++++++++++++++++++++++++++
topology/core/dihedral_type.py | 40 +++++++++++++++++++++++++
topology/core/topology.py | 45 +++++++++++++++++++++++++---
3 files changed, 135 insertions(+), 4 deletions(-)
create mode 100644 topology/core/dihedral.py
create mode 100644 topology/core/dihedral_type.py
diff --git a/topology/core/dihedral.py b/topology/core/dihedral.py
new file mode 100644
index 000000000..22e56653d
--- /dev/null
+++ b/topology/core/dihedral.py
@@ -0,0 +1,54 @@
+import warnings
+
+from topology.core.connection import Connection
+from topology.core.dihedral_type import DihedralType
+from topology.exceptions import TopologyError
+
+
+class Dihedral(Connection):
+ """A 4-partner connection between sites.
+
+ Partners
+ --------
+ connection_members: list of topology.Site
+ Should be length 4
+ connection_type : topology.DihedralType
+
+ Notes
+ -----
+ Inherits some methods from Connection:
+ __eq__, __repr__, _validate methods
+ Addiitonal _validate methods are presented
+ """
+
+ def __init__(self, connection_members=[], connection_type=None):
+ connection_members = _validate_four_partners(connection_members)
+ connection_type = _validate_dihedraltype(connection_type)
+
+ super(Dihedral, self).__init__(connection_members=connection_members,
+ connection_type=connection_type)
+
+ def __eq__(self, other):
+ if not self.connection_members == other.connection_members:
+ return False
+ if not self.connection_type == other.connection_type:
+ return False
+ return True
+
+
+def _validate_four_partners(connection_members):
+ """Ensure 4 partners are involved in Dihedral"""
+ if len(connection_members) != 4:
+ raise TopologyError("Trying to create an Dihedral "
+ "with {} connection members". format(len(connection_members)))
+
+ return connection_members
+
+
+def _validate_dihedraltype(contype):
+ """Ensure connection_type is a DihedralType """
+ if contype is None:
+ warnings.warn("Non-parametrized Dihedral detected")
+ elif not isinstance(contype, DihedralType):
+ raise TopologyError("Supplied non-DihedralType {}".format(contype))
+ return contype
diff --git a/topology/core/dihedral_type.py b/topology/core/dihedral_type.py
new file mode 100644
index 000000000..bc815f2e4
--- /dev/null
+++ b/topology/core/dihedral_type.py
@@ -0,0 +1,40 @@
+import unyt as u
+
+from topology.core.potential import Potential
+
+
+class DihedralType(Potential):
+ """A Potential between 4-bonded partners.
+
+ Parameters
+ ----------
+ name : str
+ expression : str or sympy.Expression
+ See `Potential` documentation for more information
+ parameters : dict {str, unyt.unyt_quantity}
+ See `Potential` documentation for more information
+ independent vars : set of str
+ See `Potential` documentation for more information
+
+ Notes
+ ----
+ Inherits many functions from topology.Potential:
+ __eq__, _validate functions
+ """
+
+ def __init__(self,
+ name='DihedralType',
+ expression='k * (1 + cos(n * phi - phi_eq))**2',
+ parameters={
+ 'k': 1000 * u.Unit('kJ / (deg**2)'),
+ 'theta_eq': 180 * u.deg,
+ 'n': 1*u.dimensionless
+ },
+ independent_variables={'phi'}):
+
+ super(DihedralType, self).__init__(name=name, expression=expression,
+ parameters=parameters, independent_variables=independent_variables)
+
+ def __repr__(self):
+ return "".format(self.name, id(self))
+
diff --git a/topology/core/topology.py b/topology/core/topology.py
index 6428997bc..68a49725d 100644
--- a/topology/core/topology.py
+++ b/topology/core/topology.py
@@ -6,9 +6,11 @@
from topology.core.bond import Bond
from topology.core.angle import Angle
+from topology.core.dihedral import Dihedral
from topology.core.potential import Potential
from topology.core.bond_type import BondType
from topology.core.angle_type import AngleType
+from topology.core.dihedral_type import DihedralType
from topology.exceptions import TopologyError
@@ -28,11 +30,13 @@ def __init__(self, name="Topology", box=None):
self._connections = list()
self._bonds = list()
self._angles = list()
+ self._dihedrals = list()
self._atom_types = list()
self._connection_types = list()
self._bond_types = list()
self._angle_types = list()
+ self._dihedral_types = list()
@property
def name(self):
@@ -81,6 +85,9 @@ def add_connection(self, connection):
elif isinstance(connection, Angle):
self.update_angles()
self.update_angle_types()
+ elif isinstance(connection, Dihedral):
+ self.update_dihedrals()
+ self.update_dihedral_types()
@property
def n_sites(self):
@@ -95,8 +102,8 @@ def n_bonds(self):
return len(self.bonds)
@property
- def n_angles(self):
- return len(self.angles)
+ def n_dihedrals(self):
+ return len(self.dihedrals)
@property
def sites(self):
@@ -114,6 +121,10 @@ def bonds(self):
def angles(self):
return self._angles
+ @property
+ def dihedrals(self):
+ return self._dihedrals
+
@property
def atom_types(self):
return self._atom_types
@@ -130,6 +141,10 @@ def bond_types(self):
def angle_types(self):
return self._angle_types
+ @property
+ def dihedral_types(self):
+ return self._dihedral_types
+
@property
def atom_type_expressions(self):
return list(set([atype.expression for atype in self.atom_types]))
@@ -146,23 +161,29 @@ def bond_type_expressions(self):
def angle_type_expressions(self):
return list(set([atype.expression for atype in self.angle_types]))
+ @property
+ def dihedral_type_expressions(self):
+ return list(set([atype.expression for atype in self.dihedral_types]))
+
def update_top(self):
""" Update the entire topology's attributes
Notes
-----
- Will update: sites, connections, bonds, angles,
- atom_types, connectiontypes, bondtypes, angletypes
+ Will update: sites, connections, bonds, angles, dihedrals
+ atom_types, connectiontypes, bondtypes, angletypes, dihedral_types
"""
self.update_sites()
self.update_connections()
self.update_bonds()
self.update_angles()
+ self.update_dihedrals()
self.update_atom_types()
self.update_connection_types()
self.update_bond_types()
self.update_angle_types()
+ self.update_dihedral_types()
def update_sites(self):
""" (Is this necessary?)
@@ -188,6 +209,10 @@ def update_angles(self):
""" Rebuild the angle list by filtering through connection list """
self._angles = [a for a in self.connections if isinstance(a, Angle)]
+ def update_dihedrals(self):
+ """ Rebuild the dihedral list by filtering through connection list """
+ self._dihedrals = [a for a in self.connections if isinstance(a, Dihedral)]
+
def update_atom_types(self):
""" Update the atom types based on the site list """
#self._atom_types = []
@@ -233,6 +258,18 @@ def update_angle_types(self):
elif a.connection_type not in self.angle_types:
self.angle_types.append(a.connection_type)
+ def update_dihedral_types(self):
+ """ Update the dihedral types based on the dihedral list """
+ #self._dihedral_types = []
+ for a in self.dihedrals:
+ if a.connection_type is None:
+ warnings.warn("Non-parametrized Dihedral {} detected".format(a))
+ elif not isinstance(a.connection_type, DihedralType):
+ raise TopologyError("Non-DihedralType {} found in Dihedral {}".format(
+ a.connection_type, a))
+ elif a.connection_type not in self.dihedral_types:
+ self.dihedral_types.append(a.connection_type)
+
def __repr__(self):
descr = list('<')
descr.append(self.name + ' ')
From 57ac30d08196e002aaa60d8573730ee876591037 Mon Sep 17 00:00:00 2001
From: Parashara Shamaprasad
Date: Mon, 15 Apr 2019 12:42:08 -0500
Subject: [PATCH 02/14] Added tests for dihedrals
---
topology/core/dihedral_type.py | 2 +-
topology/tests/test_topology.py | 35 +++++++++++++++++++++++++++++++++
2 files changed, 36 insertions(+), 1 deletion(-)
diff --git a/topology/core/dihedral_type.py b/topology/core/dihedral_type.py
index bc815f2e4..39a5704fa 100644
--- a/topology/core/dihedral_type.py
+++ b/topology/core/dihedral_type.py
@@ -27,7 +27,7 @@ def __init__(self,
expression='k * (1 + cos(n * phi - phi_eq))**2',
parameters={
'k': 1000 * u.Unit('kJ / (deg**2)'),
- 'theta_eq': 180 * u.deg,
+ 'phi_eq': 180 * u.deg,
'n': 1*u.dimensionless
},
independent_variables={'phi'}):
diff --git a/topology/tests/test_topology.py b/topology/tests/test_topology.py
index e9a3ef2b0..d0aa74be2 100644
--- a/topology/tests/test_topology.py
+++ b/topology/tests/test_topology.py
@@ -9,9 +9,11 @@
from topology.core.site import Site
from topology.core.bond import Bond
from topology.core.angle import Angle
+from topology.core.dihedral import Dihedral
from topology.core.atom_type import AtomType
from topology.core.bond_type import BondType
from topology.core.angle_type import AngleType
+from topology.core.dihedral_type import DihedralType
from topology.external.convert_parmed import from_parmed
from topology.tests.base_test import BaseTest
@@ -279,3 +281,36 @@ def test_angle_angletype_update(self):
assert len(top.angle_types) == 1
assert len(top.angle_type_expressions) == 1
assert len(top.atom_type_expressions) == 2
+
+ def test_dihedral_dihedraltype_update(self):
+ top = Topology()
+
+ atype1 = AtomType(expression='sigma + epsilon')
+ atype2 = AtomType(expression='sigma * epsilon')
+ site1 = Site('a', atom_type=atype1)
+ site2 = Site('b', atom_type=atype2)
+ site3 = Site('c', atom_type=atype2)
+ site4 = Site('d', atom_type=atype1)
+ atype = DihedralType()
+ dihedral = Dihedral(connection_members=[site1, site2, site3, site4], connection_type=atype)
+ top.add_site(site1)
+ top.add_site(site2)
+ top.add_site(site3)
+ top.add_site(site4)
+ top.add_connection(dihedral)
+
+ #assert top.n_connections == 1
+ #assert top.n_dihedrals == 0
+ #assert len(top.dihedral_types) == 0
+ #assert len(top.dihedral_type_expressions) == 0
+
+ #top.update_dihedral_list()
+ #assert top.n_dihedrals == 1
+ #assert len(top.dihedral_types) == 0
+ #assert len(top.dihedral_type_expressions) == 0
+
+ #top.update_dihedral_types()
+ assert top.n_dihedrals == 1
+ assert len(top.dihedral_types) == 1
+ assert len(top.dihedral_type_expressions) == 1
+ assert len(top.atom_type_expressions) == 2
From a02ab3b0e8c91482c1dcf51a9fb64fd686657583 Mon Sep 17 00:00:00 2001
From: Parashara Shamaprasad
Date: Mon, 15 Apr 2019 12:49:58 -0500
Subject: [PATCH 03/14] fixed missing n_angle in topology.py
---
topology/core/topology.py | 4 ++
topology/tests/test_dihedral.py | 68 +++++++++++++++++++++++++++++++++
2 files changed, 72 insertions(+)
create mode 100644 topology/tests/test_dihedral.py
diff --git a/topology/core/topology.py b/topology/core/topology.py
index 68a49725d..2ffb0e7e4 100644
--- a/topology/core/topology.py
+++ b/topology/core/topology.py
@@ -101,6 +101,10 @@ def n_connections(self):
def n_bonds(self):
return len(self.bonds)
+ @property
+ def n_angles(self):
+ return len(self.angles)
+
@property
def n_dihedrals(self):
return len(self.dihedrals)
diff --git a/topology/tests/test_dihedral.py b/topology/tests/test_dihedral.py
new file mode 100644
index 000000000..3998c816d
--- /dev/null
+++ b/topology/tests/test_dihedral.py
@@ -0,0 +1,68 @@
+import pytest
+
+from topology.core.dihedral import Dihedral
+from topology.core.dihedral_type import DihedralType
+from topology.core.site import Site
+from topology.tests.base_test import BaseTest
+from topology.exceptions import TopologyError
+
+
+class TestDihedral(BaseTest):
+ def test_dihedral_nonparametrized(self):
+ site1 = Site(name='site1')
+ site2 = Site(name='site2')
+ site3 = Site(name='site3')
+ site4 = Site(name='site4')
+
+ assert site1.n_connections == 0
+ assert site2.n_connections == 0
+ assert site3.n_connections == 0
+ assert site4.n_connections == 0
+
+ connect = Dihedral(connection_members=[site1, site2, site3, site4])
+
+ assert site1.n_connections == 1
+ assert site2.n_connections == 1
+ assert site3.n_connections == 1
+ assert site4.n_connections == 1
+ assert connect.connection_type is None
+
+ def test_dihedral_parametrized(self):
+ site1 = Site(name='site1')
+ site2 = Site(name='site2')
+ site3 = Site(name='site3')
+ site4 = Site(name='site4')
+
+ assert site1.n_connections == 0
+ assert site2.n_connections == 0
+ assert site3.n_connections == 0
+ assert site4.n_connections == 0
+ dihedral_type = DihedralType()
+
+ connect = Dihedral(connection_members=[site1, site2, site3, site4],
+ connection_type=dihedral_type)
+
+ assert site1.n_connections == 1
+ assert site2.n_connections == 1
+ assert site3.n_connections == 1
+ assert site4.n_connections == 1
+ assert len(connect.connection_members) == 4
+ assert connect.connection_type is not None
+
+ def test_dihedral_fake(self):
+ site1 = Site(name='site1')
+ site2 = Site(name='site2')
+ site3 = Site(name='site3')
+ site4 = Site(name='site4')
+ with pytest.raises(TopologyError):
+ Dihedral(connection_members=['fakesite1', 'fakesite2', 4.2])
+
+ def test_dihedral_fake_dihedraltype(self):
+ site1 = Site(name='site1')
+ site2 = Site(name='site2')
+ site3 = Site(name='site3')
+ site4 = Site(name='site4')
+ with pytest.raises(TopologyError):
+ Dihedral(connection_members=[site1, site2, site3, site4],
+ connection_type='Fake dihedraltype')
+
From 862c1666d5282e73856dce0887df2fca5dd099b3 Mon Sep 17 00:00:00 2001
From: Parashara Shamaprasad
Date: Fri, 17 May 2019 16:58:20 -0500
Subject: [PATCH 04/14] fixed dihedral test
---
topology/tests/test_topology.py | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/topology/tests/test_topology.py b/topology/tests/test_topology.py
index d0aa74be2..71a1133f8 100644
--- a/topology/tests/test_topology.py
+++ b/topology/tests/test_topology.py
@@ -129,6 +129,20 @@ def test_eq_angles(self):
assert ref != bad_angle_type
+ def test_eq_dihedrals(self):
+ ref = pmd.load_file(get_fn('ethane.top'),
+ xyz=get_fn('ethane.gro'))
+
+ missing_dihedral = deepcopy(ref)
+ missing_dihedral.rb_torsions[0].delete()
+
+ assert ref != missing_dihedral
+
+ bad_dihedral_type = deepcopy(ref)
+ bad_dihedral_type.rb_torsion_types[0].k = 22
+
+ assert ref != bad_dihedral_type
+
def test_eq_overall(self):
ref = pmd.load_file(get_fn('ethane.top'),
xyz=get_fn('ethane.gro'))
From 5a3d8c42715131b36ac517cfe3920ecb115cfcf7 Mon Sep 17 00:00:00 2001
From: Parashara Shamaprasad
Date: Tue, 28 May 2019 22:55:18 -0500
Subject: [PATCH 05/14] added hashing functionality to dihedral and
dihedral_type class
---
topology/core/dihedral.py | 19 ++++++++++++++-----
topology/core/dihedral_type.py | 27 ++++++++++++++++++++++++++-
2 files changed, 40 insertions(+), 6 deletions(-)
diff --git a/topology/core/dihedral.py b/topology/core/dihedral.py
index 22e56653d..ce60f3bbf 100644
--- a/topology/core/dihedral.py
+++ b/topology/core/dihedral.py
@@ -29,11 +29,20 @@ def __init__(self, connection_members=[], connection_type=None):
connection_type=connection_type)
def __eq__(self, other):
- if not self.connection_members == other.connection_members:
- return False
- if not self.connection_type == other.connection_type:
- return False
- return True
+ return hash(self) == hash(other)
+
+ def __hash__(self):
+ if self.connection_type:
+ return hash(
+ tuple(
+ (
+ self.name,
+ self.connection_type,
+ tuple(self.connection_members),
+ )
+ )
+ )
+ return hash(tuple(self.connection_members))
def _validate_four_partners(connection_members):
diff --git a/topology/core/dihedral_type.py b/topology/core/dihedral_type.py
index 39a5704fa..d8505a5d8 100644
--- a/topology/core/dihedral_type.py
+++ b/topology/core/dihedral_type.py
@@ -15,6 +15,7 @@ class DihedralType(Potential):
See `Potential` documentation for more information
independent vars : set of str
See `Potential` documentation for more information
+ member_types : list of topology.AtomType.name (str)
Notes
----
@@ -30,11 +31,35 @@ def __init__(self,
'phi_eq': 180 * u.deg,
'n': 1*u.dimensionless
},
- independent_variables={'phi'}):
+ independent_variables={'phi'},
+ member_types=[]):
super(DihedralType, self).__init__(name=name, expression=expression,
parameters=parameters, independent_variables=independent_variables)
+ self._member_types = _validate_three_member_type_names(member_types)
+
+ @property
+ def member_types(self):
+ return self._member_types
+
+ @member_types.setter
+ def member_types(self, val):
+ if self.member_types != val:
+ warnings.warn("Changing an DihedralType's constituent "
+ "member types: {} to {}".format(self.member_types, val))
+ self._member_types = _validate_four_member_type_names(val)
+
def __repr__(self):
return "".format(self.name, id(self))
+def _validate_four_member_type_names(types):
+ """Ensure 4 partners are involved in DihedralType"""
+ if len(types) != 4 and len(types) != 0:
+ raise TopologyError("Trying to create an DihedralType "
+ "with {} constituent types". format(len(types)))
+ if not all([isinstance(t, str) for t in types]):
+ raise TopologyError("Types passed to DihedralType "
+ "need to be strings corresponding to AtomType names")
+
+ return types
From b748b33d035d4a3d171d3158be51ae667aef64db Mon Sep 17 00:00:00 2001
From: Parashara Shamaprasad
Date: Fri, 4 Oct 2019 09:56:28 -0500
Subject: [PATCH 06/14] updated dihedral_type.py to reflect new changes
---
topology/core/dihedral_type.py | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/topology/core/dihedral_type.py b/topology/core/dihedral_type.py
index d8505a5d8..dc88bb701 100644
--- a/topology/core/dihedral_type.py
+++ b/topology/core/dihedral_type.py
@@ -1,6 +1,8 @@
+import warnings
import unyt as u
from topology.core.potential import Potential
+from topology.exceptions import TopologyError
class DihedralType(Potential):
@@ -37,7 +39,7 @@ def __init__(self,
super(DihedralType, self).__init__(name=name, expression=expression,
parameters=parameters, independent_variables=independent_variables)
- self._member_types = _validate_three_member_type_names(member_types)
+ self._member_types = _validate_four_member_type_names(member_types)
@property
def member_types(self):
From 4f5108a9380451aa8c7bb851495e0256d20278d4 Mon Sep 17 00:00:00 2001
From: Parashara Shamaprasad
Date: Fri, 4 Oct 2019 10:02:06 -0500
Subject: [PATCH 07/14] updated dihedral.py to reflect new connection fmt
---
topology/core/dihedral.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/topology/core/dihedral.py b/topology/core/dihedral.py
index ce60f3bbf..c6b713088 100644
--- a/topology/core/dihedral.py
+++ b/topology/core/dihedral.py
@@ -13,6 +13,8 @@ class Dihedral(Connection):
connection_members: list of topology.Site
Should be length 4
connection_type : topology.DihedralType
+ name : name of the dihedral
+ inherits the name attribute from Connection
Notes
-----
@@ -21,12 +23,12 @@ class Dihedral(Connection):
Addiitonal _validate methods are presented
"""
- def __init__(self, connection_members=[], connection_type=None):
+ def __init__(self, connection_members=[], connection_type=None, name="Dihedral"):
connection_members = _validate_four_partners(connection_members)
connection_type = _validate_dihedraltype(connection_type)
super(Dihedral, self).__init__(connection_members=connection_members,
- connection_type=connection_type)
+ connection_type=connection_type, name=name)
def __eq__(self, other):
return hash(self) == hash(other)
From 98c5ad3ec56c8ea353c00310fd783e22252a313f Mon Sep 17 00:00:00 2001
From: Parashara Shamaprasad
Date: Fri, 4 Oct 2019 10:04:07 -0500
Subject: [PATCH 08/14] updated topology.py for formatting consistency
---
topology/core/topology.py | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/topology/core/topology.py b/topology/core/topology.py
index f3faf1a85..d2d4f00f9 100644
--- a/topology/core/topology.py
+++ b/topology/core/topology.py
@@ -120,6 +120,8 @@ def add_connection(self, connection, update_types=True):
self.update_bonds()
elif isinstance(connection, Angle):
self.update_angles()
+ elif isinstance(connection, Dihedral):
+ self.update_dihedrals()
self.update_connections()
@@ -275,7 +277,7 @@ def update_angles(self):
def update_dihedrals(self):
""" Rebuild the dihedral list by filtering through connection list """
- self._dihedrals = [a for a in self.connections if isinstance(a, Dihedral)]
+ self._dihedrals = [d for d in self.connections if isinstance(d, Dihedral)]
def update_atom_types(self):
""" Update the atom types based on the site list """
@@ -325,14 +327,14 @@ def update_angle_types(self):
def update_dihedral_types(self):
""" Update the dihedral types based on the dihedral list """
#self._dihedral_types = []
- for a in self.dihedrals:
- if a.connection_type is None:
- warnings.warn("Non-parametrized Dihedral {} detected".format(a))
- elif not isinstance(a.connection_type, DihedralType):
+ for d in self.dihedrals:
+ if d.connection_type is None:
+ warnings.warn("Non-parametrized Dihedral {} detected".format(d))
+ elif not isinstance(d.connection_type, DihedralType):
raise TopologyError("Non-DihedralType {} found in Dihedral {}".format(
- a.connection_type, a))
- elif a.connection_type not in self.dihedral_types:
- self.dihedral_types.append(a.connection_type)
+ d.connection_type, d))
+ elif d.connection_type not in self.dihedral_types:
+ self.dihedral_types.add(d.connection_type)
def __repr__(self):
descr = list('<')
From b346aab401db7819921f44c7f3e63d0cc25290c1 Mon Sep 17 00:00:00 2001
From: Parashara Shamaprasad
Date: Fri, 4 Oct 2019 10:07:48 -0500
Subject: [PATCH 09/14] PEP8 -- string quotation marks
---
topology/tests/test_angle.py | 2 +-
topology/tests/test_bond.py | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/topology/tests/test_angle.py b/topology/tests/test_angle.py
index b908a7993..ed26175ab 100644
--- a/topology/tests/test_angle.py
+++ b/topology/tests/test_angle.py
@@ -44,7 +44,7 @@ def test_angle_parametrized(self):
assert site3.n_connections == 1
assert len(connect.connection_members) == 3
assert connect.connection_type is not None
- assert connect.name == "angle_name"
+ assert connect.name == 'angle_name'
def test_angle_fake(self):
site1 = Site(name='site1')
diff --git a/topology/tests/test_bond.py b/topology/tests/test_bond.py
index 8ab011d86..0ec04d270 100644
--- a/topology/tests/test_bond.py
+++ b/topology/tests/test_bond.py
@@ -38,7 +38,7 @@ def test_bond_parametrized(self):
assert site2.n_connections == 1
assert len(connect.connection_members) == 2
assert connect.connection_type is not None
- assert connect.name == "bond_name"
+ assert connect.name == 'bond_name'
def test_bond_fake(self):
site1 = Site(name='site1')
From bb6b64f078de3ec9950c535475fedfb2ac119d61 Mon Sep 17 00:00:00 2001
From: Parashara Shamaprasad
Date: Fri, 4 Oct 2019 10:15:15 -0500
Subject: [PATCH 10/14] PEP8 -- missin space
---
topology/tests/test_angle.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/topology/tests/test_angle.py b/topology/tests/test_angle.py
index ed26175ab..0ffbddc01 100644
--- a/topology/tests/test_angle.py
+++ b/topology/tests/test_angle.py
@@ -67,7 +67,7 @@ def test_angle_constituent_types(self):
site3 = Site(name='site3', position=[1,1,0], atom_type=AtomType(name='C'))
angtype = AngleType(member_types=[site1.atom_type.name, site2.atom_type.name,
site3.atom_type.name])
- ang = Angle(connection_members=[site1, site2,site3],
+ ang = Angle(connection_members=[site1, site2, site3],
connection_type=angtype)
assert 'A' in ang.connection_type.member_types
assert 'B' in ang.connection_type.member_types
From bb15a7512cd6734e4c7cd8d9eb2009d5cee03f4f Mon Sep 17 00:00:00 2001
From: Parashara Shamaprasad
Date: Fri, 4 Oct 2019 10:15:40 -0500
Subject: [PATCH 11/14] Added missing tests for dihedral class
---
topology/tests/test_dihedral.py | 41 ++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/topology/tests/test_dihedral.py b/topology/tests/test_dihedral.py
index 3998c816d..b116acb27 100644
--- a/topology/tests/test_dihedral.py
+++ b/topology/tests/test_dihedral.py
@@ -2,6 +2,7 @@
from topology.core.dihedral import Dihedral
from topology.core.dihedral_type import DihedralType
+from topology.core.atom_type import AtomType
from topology.core.site import Site
from topology.tests.base_test import BaseTest
from topology.exceptions import TopologyError
@@ -40,7 +41,8 @@ def test_dihedral_parametrized(self):
dihedral_type = DihedralType()
connect = Dihedral(connection_members=[site1, site2, site3, site4],
- connection_type=dihedral_type)
+ connection_type=dihedral_type,
+ name='dihedral_name')
assert site1.n_connections == 1
assert site2.n_connections == 1
@@ -48,6 +50,7 @@ def test_dihedral_parametrized(self):
assert site4.n_connections == 1
assert len(connect.connection_members) == 4
assert connect.connection_type is not None
+ assert connect.name == 'dihedral_name'
def test_dihedral_fake(self):
site1 = Site(name='site1')
@@ -66,3 +69,39 @@ def test_dihedral_fake_dihedraltype(self):
Dihedral(connection_members=[site1, site2, site3, site4],
connection_type='Fake dihedraltype')
+ def test_dihedral_constituent_types(self):
+ site1 = Site(name='site1', position=[0,0,0], atom_type=AtomType(name='A'))
+ site2 = Site(name='site2', position=[1,0,0], atom_type=AtomType(name='B'))
+ site3 = Site(name='site3', position=[1,1,0], atom_type=AtomType(name='C'))
+ site4 = Site(name='site4', position=[1,1,4], atom_type=AtomType(name='D'))
+ dihtype = DihedralType(member_types=[site1.atom_type.name,
+ site2.atom_type.name,
+ site3.atom_type.name,
+ site4.atom_type.name])
+ dih = Dihedral(connection_members=[site1, site2, site3, site4],
+ connection_type=dihtype)
+ assert 'A' in dih.connection_type.member_types
+ assert 'B' in dih.connection_type.member_types
+ assert 'C' in dih.connection_type.member_types
+ assert 'D' in dih.connection_type.member_types
+
+ def test_dihedral_eq(self):
+ site1 = Site(name='site1', position=[0, 0, 0])
+ site2 = Site(name='site2', position=[1, 0, 0])
+ site3 = Site(name='site3', position=[1, 1, 0])
+ site4 = Site(name='site4', position=[1, 1, 1])
+
+ ref_dihedral = Dihedral(
+ connection_members=[site1, site2, site3, site4],
+ )
+
+ same_dihedral = Dihedral(
+ connection_members=[site1, site2, site3, site4],
+ )
+
+ diff_dihedral = Dihedral(
+ connection_members=[site1, site2, site4, site3],
+ )
+
+ assert ref_dihedral == same_dihedral
+ assert ref_dihedral != diff_dihedral
\ No newline at end of file
From 6961e08c007fd6551ba04ac6e5f030d3cb1ac0d8 Mon Sep 17 00:00:00 2001
From: Parashara Shamaprasad
Date: Fri, 4 Oct 2019 10:28:46 -0500
Subject: [PATCH 12/14] Updated init.py to include dihedral and dihedral_types
---
topology/__init__.py | 3 +++
1 file changed, 3 insertions(+)
diff --git a/topology/__init__.py b/topology/__init__.py
index 020520d25..8e5f2ca33 100644
--- a/topology/__init__.py
+++ b/topology/__init__.py
@@ -6,8 +6,11 @@
from .core.connection import Connection
from .core.bond import Bond
from .core.angle import Angle
+from .core.dihedral import Dihedral
+
from .core.potential import Potential
from .core.atom_type import AtomType
from .core.bond_type import BondType
from .core.angle_type import AngleType
+from .core.dihedral_type import DihedralType
From 6a2c515d038dd48c63dc8699d5ed08d117a08b74 Mon Sep 17 00:00:00 2001
From: Parashara Shamaprasad
Date: Fri, 4 Oct 2019 10:53:32 -0500
Subject: [PATCH 13/14] missing property decorator for subtops
---
topology/core/topology.py | 1 +
1 file changed, 1 insertion(+)
diff --git a/topology/core/topology.py b/topology/core/topology.py
index d2d4f00f9..012549cfc 100644
--- a/topology/core/topology.py
+++ b/topology/core/topology.py
@@ -162,6 +162,7 @@ def n_angles(self):
def n_dihedrals(self):
return len(self.dihedrals)
+ @property
def subtops(self):
return self._subtops
From bdca0f50573a3bf916451f6af8c15d33daf8c1d9 Mon Sep 17 00:00:00 2001
From: "Matthew W. Thompson"
Date: Fri, 11 Oct 2019 10:21:17 -0500
Subject: [PATCH 14/14] Remove commented code
---
topology/tests/test_topology.py | 53 ++-------------------------------
1 file changed, 2 insertions(+), 51 deletions(-)
diff --git a/topology/tests/test_topology.py b/topology/tests/test_topology.py
index 64c131e98..a74d99bbb 100644
--- a/topology/tests/test_topology.py
+++ b/topology/tests/test_topology.py
@@ -241,14 +241,8 @@ def test_top_update(self):
top.add_site(site1)
site2 = Site(name='site2', atom_type=atomtype)
top.add_site(site2)
+
assert top.n_sites == 2
- #assert len(top.atom_types) == 0
- #assert len(top.atom_type_expressions) == 0
- #assert top.n_connections == 0
- #assert len(top.connection_types) == 0
- #assert len(top.connection_type_expressions) == 0
- #top.update_atom_types()
- #assert top.n_sites == 2
assert len(top.atom_types) == 1
assert len(top.atom_type_expressions) == 1
assert top.n_connections == 0
@@ -260,13 +254,7 @@ def test_top_update(self):
connection_12 = Bond(connection_members=[site1, site2],
connection_type=ctype)
top.add_connection(connection_12)
- #assert top.n_sites == 2
- #assert len(top.atom_types) == 1
- #assert len(top.atom_type_expressions) == 1
- #assert top.n_connections == 1
- #assert len(top.connection_types) == 0
- #assert len(top.connection_type_expressions) == 0
- #top.update_connection_types()
+
assert top.n_sites == 2
assert len(top.atom_types) == 1
assert len(top.atom_type_expressions) == 1
@@ -302,11 +290,7 @@ def test_atomtype_update(self):
site2 = Site('b', atom_type=atype2)
top.add_site(site1)
top.add_site(site2)
- #assert top.n_sites == 2
- #assert len(top.atom_types) == 0
- #assert len(top.atom_type_expressions) == 0
- #top.update_atom_types()
assert top.n_sites == 2
assert len(top.atom_types) == 2
assert len(top.atom_type_expressions) == 2
@@ -324,17 +308,6 @@ def test_bond_bondtype_update(self):
top.add_site(site2)
top.add_connection(bond)
- #assert top.n_connections == 1
- #assert top.n_bonds == 0
- #assert len(top.bond_types) == 0
- #assert len(top.bond_type_expressions) == 0
-
- #top.update_bond_list()
- #assert top.n_bonds == 1
- #assert len(top.bond_types) == 0
- #assert len(top.bond_type_expressions) == 0
-
- #top.update_bond_types()
assert top.n_bonds == 1
assert len(top.bond_types) == 1
assert len(top.bond_type_expressions) == 1
@@ -354,17 +327,6 @@ def test_angle_angletype_update(self):
top.add_site(site3)
top.add_connection(angle)
- #assert top.n_connections == 1
- #assert top.n_angles == 0
- #assert len(top.angle_types) == 0
- #assert len(top.angle_type_expressions) == 0
-
- #top.update_angle_list()
- #assert top.n_angles == 1
- #assert len(top.angle_types) == 0
- #assert len(top.angle_type_expressions) == 0
-
- #top.update_angle_types()
assert top.n_angles == 1
assert len(top.angle_types) == 1
assert len(top.angle_type_expressions) == 1
@@ -387,17 +349,6 @@ def test_dihedral_dihedraltype_update(self):
top.add_site(site4)
top.add_connection(dihedral)
- #assert top.n_connections == 1
- #assert top.n_dihedrals == 0
- #assert len(top.dihedral_types) == 0
- #assert len(top.dihedral_type_expressions) == 0
-
- #top.update_dihedral_list()
- #assert top.n_dihedrals == 1
- #assert len(top.dihedral_types) == 0
- #assert len(top.dihedral_type_expressions) == 0
-
- #top.update_dihedral_types()
assert top.n_dihedrals == 1
assert len(top.dihedral_types) == 1
assert len(top.dihedral_type_expressions) == 1