diff --git a/topology/core/virtualsite.py b/topology/core/virtualsite.py new file mode 100644 index 000000000..a030e899b --- /dev/null +++ b/topology/core/virtualsite.py @@ -0,0 +1,73 @@ +import warnings +from topology.core.site import Site +from topology.core.potential import Potential + + +class VirtualSite(object): + """A virtual site construction + + Partners + -------- + virtual_site: topology.site + An instance of topology.site that is the virtual site + virtual_site_members: list of topology.Site + Should be length 2 or 3 + virtual_site_type: topology.Potential + An instance of topology.Potential that describes + the virtual site function and parameters of this interaction + name: name of the virtual site + """ + + def __init__(self, virtual_site, virtual_site_members=[], virtual_site_type=None, name="VirtualSite"): + if virtual_site_members is None: + virtual_site_members = tuple() + + # TODO: validate virtual site members + #self._virtual_site_members = _validate_virtual_site_members(virtual_site_members) + self._virtual_site = virtual_site + self._virtual_site_members = virtual_site_members + self._virtual_site_type = _validate_vs_type(virtual_site_type) + self._name = _validate_name(name) + # TODO: update members + #self._update_members() + + @property + def virtual_site(self): + return self._virtual_site + + @property + def virtual_site_members(self): + return self._virtual_site_members + + @property + def virtual_site_type(self): + return self._virtual_site_type + + @property + def name(self): + return self._name + + @name.setter + def name(self, vsname): + self._name = _validate_name(vsname) + + def __repr__(self): + descr = '<{} Virtual Site, id {}'.format( + self.virtual_site_type, id(self)) + if self.name: + descr += ', name {}'.format(self.name) + descr += '>' + + return descr + +def _validate_vs_type(c_type): + if c_type is None: + warnings.warn("Non-parametrized virtual site detected") + elif not isinstance(c_type, Potential): + raise TopologyError("Supplied non-Potential {}".format(c_type)) + return c_type + +def _validate_name(conname): + if not isinstance(conname, str): + raise TopologyError("Supplied name {} is not a string".format(conname)) + return conname diff --git a/topology/core/virtualsite_type.py b/topology/core/virtualsite_type.py new file mode 100644 index 000000000..f9858ab41 --- /dev/null +++ b/topology/core/virtualsite_type.py @@ -0,0 +1,68 @@ +import warnings +import unyt as u + +from topology.core.potential import Potential +from topology.exceptions import TopologyError +from topology.utils._constants import DIHEDRAL_TYPE_DICT + +class VirtualSiteType(Potential): + """A virtual site construction. + + 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 + member_types : list of topology.AtomType.name (str) + topology: topology.core.Topology, the topology of which this virtual site type is a part of, default=None + set_ref: (str), the string name of the bookkeeping set in topology class. + + Notes + ---- + Inherits many functions from topology.Potential: + __eq__, _validate functions + """ + + def __init__(self, + name='VirtualSiteType', + expression='1 - a', + parameters=None, + independent_variables=None, + member_types=None, + topology=None, + set_ref='virtualsite_type_set'): + if parameters is None: + parameters = { + 'a': 0.35 * u.dimensionless + } + + if member_types is None: + member_types = list() + + super(VirtualSiteType, self).__init__(name=name, expression=expression, + parameters=parameters, independent_variables=independent_variables, + topology=topology) + #self._set_ref = VIRTUALSITE_TYPE_DICT + self._member_types = member_types + + @property + def set_ref(self): + return self._set_ref + + @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 VirtualSiteType'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)) diff --git a/topology/lib/virtual_templates.py b/topology/lib/virtual_templates.py new file mode 100644 index 000000000..f4f1b8ddd --- /dev/null +++ b/topology/lib/virtual_templates.py @@ -0,0 +1,40 @@ +from topology.core.potential import Potential + + +class VirtualSiteTemplate(Potential): + def __init__(self, + name='VirtualSiteTemplate', + expression='1 - a', + independent_variables=None, + template=True): + + super(VirtualSiteTemplate, self).__init__( + name=name, + expression=expression, + independent_variables=independent_variables, + template=template, + ) + +class TwoSiteConstruction(VirtualSiteTemplate): + def __init__(self, + name='TwoSiteConstruction', + expression='1 - a)', + independent_variables=None): + super(PotentialTemplate, self).__init__( + name=name, + expression=expression, + independent_variables=independent_variables, + template=True, + ) + +class ThreeSiteConstruction(VirtualSiteTemplate): + def __init__(self, + name='ThreeSiteConstruction', + expression='1 - a - b)', + independent_variables=None): + super(PotentialTemplate, self).__init__( + name=name, + expression=expression, + independent_variables=independent_variables, + template=True, + )