def test_double_conversion(self):

        # Pick some OPLS parameters at random
        params = { 'k0' : 1.38   * u.Unit('kJ/mol'),
                   'k1' : -0.51  * u.Unit('kJ/mol'),
                   'k2' : 2.2    * u.Unit('kJ/mol'),
                   'k3' : -0.25  * u.Unit('kJ/mol'),
                   'k4' : 1.44   * u.Unit('kJ/mol')
                 }

        name = OPLSTorsionPotential().name
        expression = OPLSTorsionPotential().expression
        variables = OPLSTorsionPotential().independent_variables

        opls_connection_type = DihedralType(
                name=name,
                expression=expression,
                independent_variables=variables,
                parameters=params)

        # Convert connection to RB
        ryckaert_connection_type = convert_opls_to_ryckaert(
                opls_connection_type)

        # Convert connection back to OPLS
        final_connection_type = convert_ryckaert_to_opls(
                ryckaert_connection_type)

        assert np.allclose([*opls_connection_type.parameters.values()],
                           [*final_connection_type.parameters.values()])
예제 #2
0
파일: ff_utils.py 프로젝트: bc118/gmso
def _parse_unit_string(string):
    """
    Converts a string with unyt units and physical constants to a taggable unit value
    """
    string = string.replace("deg", "__deg")
    string = string.replace("rad", "__rad")
    expr = sympify(str(string))

    sympy_subs = []
    unyt_subs = []

    for symbol in expr.free_symbols:
        try:
            symbol_unit = _unyt_dictionary[symbol.name.strip('_')]
        except KeyError:
            raise u.exceptions.UnitParseError(
                    "Could not find unit symbol",
                    "'{}' in the provided symbols.".format(symbol.name)
                    )
        if isinstance(symbol_unit, u.Unit):
            sympy_subs.append((symbol.name, symbol_unit.base_value))
            unyt_subs.append((symbol.name, symbol_unit.get_base_equivalent().expr))
        elif isinstance(symbol_unit, u.unyt_quantity):
            sympy_subs.append((symbol.name, float(symbol_unit.in_base().value)))
            unyt_subs.append((symbol.name, symbol_unit.units.get_base_equivalent().expr))

    return u.Unit(float(expr.subs(sympy_subs)) * u.Unit(str(expr.subs(unyt_subs))))
예제 #3
0
    def test_double_conversion(self, templates):

        # Pick some OPLS parameters at random
        params = {
            'k0': 1.38 * u.Unit('kJ/mol'),
            'k1': -0.51 * u.Unit('kJ/mol'),
            'k2': 2.2 * u.Unit('kJ/mol'),
            'k3': -0.25 * u.Unit('kJ/mol'),
            'k4': 1.44 * u.Unit('kJ/mol')
        }

        opls_torsion_potential = templates['OPLSTorsionPotential']

        name = opls_torsion_potential.name
        expression = opls_torsion_potential.expression
        variables = opls_torsion_potential.independent_variables

        opls_connection_type = DihedralType(name=name,
                                            expression=expression,
                                            independent_variables=variables,
                                            parameters=params)

        # Convert connection to RB
        ryckaert_connection_type = convert_opls_to_ryckaert(
            opls_connection_type)

        # Convert connection back to OPLS
        final_connection_type = convert_ryckaert_to_opls(
            ryckaert_connection_type)

        assert_allclose_units([*opls_connection_type.parameters.values()],
                              [*final_connection_type.parameters.values()],
                              rtol=1e-5,
                              atol=1e-8)
예제 #4
0
파일: test_units.py 프로젝트: langmm/unyt
def test_micro_prefix():
    import unyt as u

    # both versions of unicode mu work correctly
    assert u.um == u.µm
    assert u.um == u.μm

    # parsing both versions works as well
    assert u.ug == u.Unit("µg")
    assert u.ug == u.Unit("μg")
예제 #5
0
 def test_new_atom_type(self, charge, mass):
     new_type = AtomType(name='mytype', charge=charge, mass=mass,
             parameters={'sigma': 1 * u.nm,
                 'epsilon': 10 * u.Unit('kcal / mol')},
             independent_variables={'r'})
     assert new_type.name == 'mytype'
     assert_allclose_units(new_type.charge, charge, rtol=1e-5, atol=1e-8)
     assert_allclose_units(new_type.parameters['sigma'], 1 * u.nm, rtol=1e-5, atol=1e-8)
     assert_allclose_units(new_type.parameters['epsilon'], 10 * u.Unit('kcal / mol'), rtol=1e-5, atol=1e-8)
     assert_allclose_units(new_type.mass, mass, rtol=1e-5, atol=1e-8)
예제 #6
0
    def test_spce_xml(self):
        spce = ForceField(get_path('spce.xml'))

        assert len(spce.atom_types) == 2
        assert len(spce.bond_types) == 1
        assert len(spce.angle_types) == 1
        assert len(spce.dihedral_types) == 0

        # Store expected expressions in list
        ref_exprs = [
            sympy.sympify(expr) for expr in [
                "4*epsilon*((sigma/r)**12 - (sigma/r)**6)",
                "0.5 * k * (r-r_eq)**2",
                "0.5 * k * (theta-theta_eq)**2",
            ]
        ]

        assert allclose(spce.atom_types['opls_116'].charge,
                        -0.8476 * u.elementary_charge)
        assert allclose(spce.atom_types['opls_117'].charge,
                        0.4238 * u.elementary_charge)

        assert sympy.simplify(spce.atom_types['opls_116'].expression -
                              ref_exprs[0]) == 0
        assert sympy.simplify(spce.atom_types['opls_117'].expression -
                              ref_exprs[0]) == 0
        assert sympy.simplify(spce.bond_types['opls_116~opls_117'].expression -
                              ref_exprs[1]) == 0
        assert sympy.simplify(
            spce.angle_types['opls_117~opls_116~opls_117'].expression -
            ref_exprs[2]) == 0

        assert allclose(spce.atom_types['opls_116'].parameters['sigma'],
                        0.316557 * u.nm)
        assert allclose(spce.atom_types['opls_116'].parameters['epsilon'],
                        0.650194 * u.Unit('kJ/mol'))
        assert allclose(spce.atom_types['opls_117'].parameters['sigma'],
                        0.1 * u.nm)
        assert allclose(spce.atom_types['opls_117'].parameters['epsilon'],
                        0.0 * u.Unit('kJ/mol'))

        assert allclose(
            spce.bond_types['opls_116~opls_117'].parameters['r_eq'],
            0.1 * u.nm)
        assert allclose(spce.bond_types['opls_116~opls_117'].parameters['k'],
                        345000.0 * u.Unit('kJ/(mol*nm**2)'))

        assert allclose(
            spce.angle_types['opls_117~opls_116~opls_117'].
            parameters['theta_eq'], 109.47 * u.degree)
        assert allclose(
            spce.angle_types['opls_117~opls_116~opls_117'].parameters['k'],
            383.0 * u.Unit('kJ/mol/rad**2'))
예제 #7
0
    def test_noble_mie_xml(self):
        ff = ForceField(get_path('noble_mie.xml'))
        templates = PotentialTemplateLibrary()
        ref_expr = templates['MiePotential'].expression

        assert len(ff.atom_types) == 4
        assert len(ff.bond_types) == 0
        assert len(ff.angle_types) == 0
        assert len(ff.dihedral_types) == 0

        for (name, atom_type) in ff.atom_types.items():
            assert sympy.simplify(atom_type.expression - ref_expr) == 0

        assert allclose(ff.atom_types['Ne'].parameters['epsilon'],
                        0.26855713 * u.Unit('kJ/mol'))
        assert allclose(ff.atom_types['Ne'].parameters['sigma'],
                        2.794 * u.Angstrom)
        assert allclose(ff.atom_types['Ne'].parameters['n'],
                        11 * u.dimensionless)
        assert allclose(ff.atom_types['Ne'].parameters['m'],
                        6 * u.dimensionless)
        assert ff.atom_types['Ne'].charge.value == 0

        assert allclose(ff.atom_types['Ar'].parameters['epsilon'],
                        1.01519583 * u.Unit('kJ/mol'))
        assert allclose(ff.atom_types['Ar'].parameters['sigma'],
                        3.405 * u.Angstrom)
        assert allclose(ff.atom_types['Ar'].parameters['n'],
                        13 * u.dimensionless)
        assert allclose(ff.atom_types['Ar'].parameters['m'],
                        6 * u.dimensionless)
        assert ff.atom_types['Ar'].charge.value == 0

        assert allclose(ff.atom_types['Kr'].parameters['epsilon'],
                        1.46417678 * u.Unit('kJ/mol'))
        assert allclose(ff.atom_types['Kr'].parameters['sigma'],
                        3.645 * u.Angstrom)
        assert allclose(ff.atom_types['Kr'].parameters['n'],
                        14 * u.dimensionless)
        assert allclose(ff.atom_types['Kr'].parameters['m'],
                        6 * u.dimensionless)
        assert ff.atom_types['Kr'].charge.value == 0

        assert allclose(ff.atom_types['Xe'].parameters['epsilon'],
                        2.02706587 * u.Unit('kJ/mol'))
        assert allclose(ff.atom_types['Xe'].parameters['sigma'],
                        3.964 * u.Angstrom)
        assert allclose(ff.atom_types['Xe'].parameters['n'],
                        14 * u.dimensionless)
        assert allclose(ff.atom_types['Xe'].parameters['m'],
                        6 * u.dimensionless)
        assert ff.atom_types['Xe'].charge.value == 0
예제 #8
0
    def test_tip3p_force_field(self):
        water = ForceField(get_path('tip3p.xml'))
        assert len(water.atom_types) == 2
        assert len(water.bond_types) == 1
        assert len(water.angle_types) == 1
        assert len(water.dihedral_types) == 0

        # Store expected expressions in list
        ref_exprs = [
            sympy.sympify(expr) for expr in [
                "4*epsilon*((sigma/r)**12 - (sigma/r)**6)",
                "0.5 * k * (r-r_eq)**2",
                "0.5 * k * (theta-theta_eq)**2",
            ]
        ]

        assert water.atom_types['opls_111'].charge.value == -0.834
        assert water.atom_types['opls_112'].charge.value == 0.417

        assert sympy.simplify(water.atom_types['opls_111'].expression -
                              ref_exprs[0]) == 0
        assert sympy.simplify(water.atom_types['opls_112'].expression -
                              ref_exprs[0]) == 0
        assert sympy.simplify(
            water.bond_types['opls_111~opls_112'].expression -
            ref_exprs[1]) == 0
        assert sympy.simplify(
            water.angle_types['opls_112~opls_111~opls_112'].expression -
            ref_exprs[2]) == 0

        assert allclose(water.atom_types['opls_111'].parameters['sigma'],
                        0.315061 * u.nm)
        assert allclose(water.atom_types['opls_111'].parameters['epsilon'],
                        0.636386 * u.Unit('kJ/mol'))
        assert allclose(water.atom_types['opls_112'].parameters['sigma'],
                        1.0 * u.nm)
        assert allclose(water.atom_types['opls_112'].parameters['epsilon'],
                        0.0 * u.Unit('kJ/mol'))

        assert allclose(
            water.bond_types['opls_111~opls_112'].parameters['r_eq'],
            0.09572 * u.nm)
        assert allclose(water.bond_types['opls_111~opls_112'].parameters['k'],
                        502416.0 * u.Unit('kJ/(mol*nm**2)'))

        assert allclose(
            water.angle_types['opls_112~opls_111~opls_112'].
            parameters['theta_eq'], 1.824218134 * u.radian)
        assert allclose(
            water.angle_types['opls_112~opls_111~opls_112'].parameters['k'],
            682.02 * u.Unit('kJ/(mol*rad**2)'))
예제 #9
0
    def test_carbon_force_field(self):
        carbon = ForceField(get_path('carbon.xml'))

        assert len(carbon.atom_types) == 1
        assert len(carbon.bond_types) == 1
        assert len(carbon.angle_types) == 1
        assert len(carbon.dihedral_types) == 1

        # Store expected expressions in list
        ref_exprs = [
            sympy.sympify(expr) for expr in [
                "4*epsilon*((sigma/r)**12 - (sigma/r)**6)",
                "0.5 * k * (r-r_eq)**2",
                "0.5 * k * (theta-theta_eq)**2",
                "k * (1 + cos(n * theta - theta_0))",
            ]
        ]

        assert carbon.atom_types['C'].charge.value == 0

        assert sympy.simplify(carbon.atom_types['C'].expression -
                              ref_exprs[0]) == 0
        assert sympy.simplify(carbon.bond_types['C~C'].expression -
                              ref_exprs[1]) == 0
        assert sympy.simplify(carbon.angle_types['C~C~C'].expression -
                              ref_exprs[2]) == 0
        assert sympy.simplify(carbon.dihedral_types['*~C~C~*'].expression -
                              ref_exprs[3]) == 0

        assert allclose(carbon.atom_types['C'].parameters['sigma'],
                        0.339966950842 * u.nm)
        assert allclose(carbon.atom_types['C'].parameters['epsilon'],
                        0.359824 * u.Unit('kJ/mol'))

        assert allclose(carbon.bond_types['C~C'].parameters['r_eq'],
                        0.1324 * u.nm)
        assert allclose(carbon.bond_types['C~C'].parameters['k'],
                        493460.96 * u.Unit('kJ/(mol*nm**2)'))

        assert allclose(carbon.angle_types['C~C~C'].parameters['theta_eq'],
                        2.12598556185 * u.radian)
        assert allclose(carbon.angle_types['C~C~C'].parameters['k'],
                        584.42112 * u.Unit('kJ/(mol*rad**2)'))

        assert allclose(carbon.dihedral_types['*~C~C~*'].parameters['k'],
                        27.8236 * u.Unit('kJ/mol'))
        assert allclose(carbon.dihedral_types['*~C~C~*'].parameters['n'],
                        2 * u.dimensionless)
        assert allclose(carbon.dihedral_types['*~C~C~*'].parameters['theta_0'],
                        np.pi * u.radian)
예제 #10
0
    def test_opls_to_ryckaert(self, templates):

        # Pick some OPLS parameters at random
        params = {
            "k0": 1.38 * u.Unit("kJ/mol"),
            "k1": -0.51 * u.Unit("kJ/mol"),
            "k2": 2.2 * u.Unit("kJ/mol"),
            "k3": -0.25 * u.Unit("kJ/mol"),
            "k4": 1.44 * u.Unit("kJ/mol"),
        }

        opls_torsion_potential = templates["OPLSTorsionPotential"]
        name = opls_torsion_potential.name
        expression = opls_torsion_potential.expression
        variables = opls_torsion_potential.independent_variables

        opls_connection_type = DihedralType(
            name=name,
            expression=expression,
            independent_variables=variables,
            parameters=params,
        )

        # Convert connection to RB
        ryckaert_connection_type = convert_opls_to_ryckaert(
            opls_connection_type)

        # Pick some angles to check
        angles = [-2.38, -1.31, -0.44, 0.0, 0.26, 0.92, 1.84, 3.10]

        for angle in angles:
            assert np.isclose(
                float(
                    ryckaert_connection_type.expression.subs([
                        (param, val) for param, val in {
                            **ryckaert_connection_type.parameters,
                            "phi":
                            angle - np.pi,
                        }.items()
                    ])),
                float(
                    opls_connection_type.expression.subs([
                        (param, val) for param, val in {
                            **opls_connection_type.parameters,
                            "phi": angle,
                        }.items()
                    ])),
            )
예제 #11
0
    def __init__(
        self,
        name="AngleType",
        expression=None,
        parameters=None,
        independent_variables=None,
        potential_expression=None,
        member_types=None,
        topology=None,
        tags=None,
    ):
        if potential_expression is None:
            if expression is None:
                expression = "0.5 * k * (theta-theta_eq)**2"

            if parameters is None:
                parameters = {
                    "k": 1000 * u.Unit("kJ / (deg**2)"),
                    "theta_eq": 180 * u.deg,
                }
            if independent_variables is None:
                independent_variables = {"theta"}

        super(AngleType, self).__init__(
            name=name,
            expression=expression,
            parameters=parameters,
            independent_variables=independent_variables,
            potential_expression=potential_expression,
            topology=topology,
            member_types=member_types,
            set_ref=ANGLE_TYPE_DICT,
            tags=tags,
        )
예제 #12
0
def _bond_types_from_pmd(structure, bond_types_members_map=None):
    """ Helper function to convert GMSO BondType

    This function take in a Parmed Structure, iterate through its
    bond_types, create a corresponding GMSO.BondType, and finally
    return a dictionary containing all pairs of pmd.BondType
    and GMSO.BondType

    Parameters
    ----------
    structure: pmd.Structure
        Parmed Structure that needed to be converted.
    bond_types_members_map: optional, dict, default=None
        The member types (atomtype string) for each atom associated with the bond_types the structure

    Returns
    -------
    pmd_top_bondtypes : dict
        A dictionary linking a pmd.BondType object to its
        corresponding GMSO.BondType object.
    """
    pmd_top_bondtypes = dict()
    bond_types_members_map = _assert_dict(bond_types_members_map,
                                          'bond_types_members_map')
    for btype in structure.bond_types:
        bond_params = {
            'k': (2 * btype.k * u.Unit('kcal / (angstrom**2 * mol)')),
            'r_eq': btype.req * u.angstrom
        }

        member_types = bond_types_members_map.get(id(btype))
        top_bondtype = gmso.BondType(parameters=bond_params,
                                     member_types=member_types)
        pmd_top_bondtypes[btype] = top_bondtype
    return pmd_top_bondtypes
예제 #13
0
    def __init__(self,
                 name='AngleType',
                 expression='0.5 * k * (theta-theta_eq)**2',
                 parameters=None,
                 independent_variables=None,
                 member_types=None,
                 topology=None,
                 tags=None):
        if parameters is None:
            parameters = {
                'k': 1000 * u.Unit('kJ / (deg**2)'),
                'theta_eq': 180 * u.deg
            }
        if independent_variables is None:
            independent_variables = {'theta'}

        super(AngleType,
              self).__init__(name=name,
                             expression=expression,
                             parameters=parameters,
                             independent_variables=independent_variables,
                             topology=topology,
                             member_types=member_types,
                             set_ref=ANGLE_TYPE_DICT,
                             tags=tags)
예제 #14
0
    def __init__(
        self,
        name="DihedralType",
        expression=None,
        parameters=None,
        independent_variables=None,
        potential_expression=None,
        member_types=None,
        topology=None,
        tags=None,
    ):
        if potential_expression is None:
            if expression is None:
                expression = "k * (1 + cos(n * phi - phi_eq))**2"

            if parameters is None:
                parameters = {
                    "k": 1000 * u.Unit("kJ / (deg**2)"),
                    "phi_eq": 180 * u.deg,
                    "n": 1 * u.dimensionless,
                }
            if independent_variables is None:
                independent_variables = {"phi"}

        super(DihedralType, self).__init__(
            name=name,
            expression=expression,
            parameters=parameters,
            independent_variables=independent_variables,
            potential_expression=potential_expression,
            topology=topology,
            member_types=member_types,
            set_ref=DIHEDRAL_TYPE_DICT,
            tags=tags,
        )
예제 #15
0
    def __init__(self,
                 name='DihedralType',
                 expression='k * (1 + cos(n * phi - phi_eq))**2',
                 parameters=None,
                 independent_variables=None,
                 member_types=None,
                 topology=None,
                 set_ref='dihedral_type_set'):
        if parameters is None:
            parameters = {
                'k': 1000 * u.Unit('kJ / (deg**2)'),
                'phi_eq': 180 * u.deg,
                'n': 1 * u.dimensionless
            }
        if independent_variables is None:
            independent_variables = {'phi'}

        if member_types is None:
            member_types = list()

        super(DihedralType, self).__init__(name=name, expression=expression,
                                           parameters=parameters, independent_variables=independent_variables,
                                           topology=topology)
        self._set_ref = DIHEDRAL_TYPE_DICT
        self._member_types = _validate_four_member_type_names(member_types)
예제 #16
0
def main():

    # Input conditions
    temperature = 298.0 * u.K
    mus = np.arange(-58, -42, 2) * u.Unit("kJ/mol")

    # Output
    pressures = []

    for mu in mus:
        dirname = f"T_{temperature:0.1f}_mu_{mu:.1f}".replace(
            " ", "_"
        ).replace(
            "/", "-"
        )
        thermo_path = "../gcmc_bulk/" + dirname + "/prod.out.prp"
        thermo = ThermoProps(thermo_path)
        pressures.append(thermo.prop("Pressure").mean())

    pressures = u.unyt_array(pressures)

    df = pd.DataFrame(
        columns=["mu-cassandra_kJmol", "pressure_bar"]
    )
    df["mu-cassandra_kJmol"] = mus.to_value("kJ/mol")
    df["pressure_bar"] = pressures.to_value("bar")
    df.to_csv("results_gcmc_bulk.csv")
예제 #17
0
    def __init__(
        self,
        name="BondType",
        expression=None,
        parameters=None,
        independent_variables=None,
        potential_expression=None,
        member_types=None,
        topology=None,
        tags=None,
    ):
        if potential_expression is None:
            if expression is None:
                expression = "0.5 * k * (r-r_eq)**2"

            if parameters is None:
                parameters = {
                    "k": 1000 * u.Unit("kJ / (nm**2)"),
                    "r_eq": 0.14 * u.nm,
                }
            if independent_variables is None:
                independent_variables = {"r"}

        super(BondType, self).__init__(
            name=name,
            expression=expression,
            parameters=parameters,
            independent_variables=independent_variables,
            potential_expression=potential_expression,
            topology=topology,
            member_types=member_types,
            set_ref=BOND_TYPE_DICT,
            tags=tags,
        )
예제 #18
0
    def __init__(self,
                 name='BondType',
                 expression='0.5 * k * (r-r_eq)**2',
                 parameters=None,
                 independent_variables=None,
                 member_types=None,
                 topology=None,
                 tags=None):
        if parameters is None:
            parameters = {
                'k': 1000 * u.Unit('kJ / (nm**2)'),
                'r_eq': 0.14 * u.nm
            }
        if independent_variables is None:
            independent_variables = {'r'}

        super(BondType, self).__init__(
            name=name,
            expression=expression,
            parameters=parameters,
            independent_variables=independent_variables,
            topology=topology,
            member_types=member_types,
            set_ref=BOND_TYPE_DICT,
            tags=tags
        )
예제 #19
0
 def _get_units(self, q) -> unyt.Unit:
     """Get the units of an object."""
     try:
         units = q.units
     except AttributeError:
         units = unyt.dimensionless
     return unyt.Unit(units, registry=self.registry)
예제 #20
0
    def __init__(self,
                 name='ImproperType',
                 expression='0.5 * k * ((phi - phi_eq))**2',
                 parameters=None,
                 independent_variables=None,
                 member_types=None,
                 topology=None,
                 tags=None):
        if parameters is None:
            parameters = {
                'k': 1000 * u.Unit('kJ / (deg**2)'),
                'phi_eq': 0 * u.deg,
            }
        if independent_variables is None:
            independent_variables = {'phi'}

        super(ImproperType,
              self).__init__(name=name,
                             expression=expression,
                             parameters=parameters,
                             independent_variables=independent_variables,
                             topology=topology,
                             member_types=member_types,
                             set_ref=IMPROPER_TYPE_DICT,
                             tags=tags)
예제 #21
0
def _bond_types_from_pmd(structure):
    """ Helper function to convert GMSO BondType

    This function take in a Parmed Structure, iterate through its
    bond_types, create a corresponding GMSO.BondType, and finally
    return a dictionary containing all pairs of pmd.BondType
    and GMSO.BondType

    Parameter
    ----------
        structure: pmd.Structure
            Parmed Structure that needed to be converted.

    Return
    ------
        pmd_top_bondtypes : dict
            A dictionary linking a pmd.BondType object to its
            corresponding GMSO.BondType object.
    """
    pmd_top_bondtypes = dict()
    for btype in structure.bond_types:
        bond_params = {
            'k': (2 * btype.k * u.Unit('kcal / (angstrom**2 * mol)')),
            'r_eq': btype.req * u.angstrom
        }

        top_bondtype = gmso.BondType(parameters=bond_params)
        pmd_top_bondtypes[btype] = top_bondtype
    return pmd_top_bondtypes
예제 #22
0
def _angle_types_from_pmd(structure):
    """ Helper function to convert GMSO AngleType

    This function take in a Parmed Structure, iterate through its
    angle_types, create a corresponding GMSO.AngleType, and finally
    return a dictionary containing all pairs of pmd.AngleType
    and GMSO.AngleType

    Parameter
    ----------
        structure: pmd.Structure
            Parmed Structure that needed to be converted.

    Return
    ------
        pmd_top_angletypes : dict
            A dictionary linking a pmd.AngleType object to its
            corresponding GMSO.AngleType object.
    """
    pmd_top_angletypes = dict()
    for angletype in structure.angle_types:
        angle_params = {
            'k': (2 * angletype.k * u.Unit('kcal / (rad**2 * mol)')),
            'theta_eq': (angletype.theteq * u.degree)
        }
        # Do we need to worry about Urey Bradley terms
        # For Urey Bradley:
        # k in (kcal/(angstrom**2 * mol))
        # r_eq in angstrom
        top_angletype = gmso.AngleType(parameters=angle_params)
        pmd_top_angletypes[angletype] = top_angletype
    return pmd_top_angletypes
예제 #23
0
    def __init__(self,
                 name='BondType',
                 expression='0.5 * k * (r-r_eq)**2',
                 parameters=None,
                 independent_variables=None,
                 member_types=None,
                 topology=None,
                 set_ref='bond_type_set'):
        if parameters is None:
            parameters = {
                'k': 1000 * u.Unit('kJ / (nm**2)'),
                'r_eq': 0.14 * u.nm
            }
        if independent_variables is None:
            independent_variables = {'r'}

        if member_types is None:
            member_types = list()

        super(BondType,
              self).__init__(name=name,
                             expression=expression,
                             parameters=parameters,
                             independent_variables=independent_variables,
                             topology=topology)
        self._set_ref = BOND_TYPE_DICT
        self._member_types = _validate_two_member_type_names(member_types)
예제 #24
0
    def __init__(self,
                 name='AtomType',
                 mass=0.0 * u.gram / u.mol,
                 charge=0.0 * u.elementary_charge,
                 expression='4*epsilon*((sigma/r)**12 - (sigma/r)**6)',
                 parameters=None,
                 independent_variables=None,
                 atomclass='',
                 doi='',
                 overrides=None,
                 definition='',
                 description='',
                 topology=None):
        if parameters is None:
            parameters = {'sigma': 0.3 * u.nm, 'epsilon': 0.3 * u.Unit('kJ')}
        if independent_variables is None:
            independent_variables = {'r'}

        if overrides is None:
            overrides = set()

        super(AtomType,
              self).__init__(name=name,
                             expression=expression,
                             parameters=parameters,
                             independent_variables=independent_variables,
                             topology=topology,
                             mass=mass,
                             charge=charge,
                             atomclass=atomclass,
                             doi=doi,
                             overrides=overrides,
                             description=description,
                             definition=definition,
                             set_ref=ATOM_TYPE_DICT)
예제 #25
0
    def __init__(self,
                 name='DihedralType',
                 expression='k * (1 + cos(n * phi - phi_eq))**2',
                 parameters=None,
                 independent_variables=None,
                 member_types=None,
                 topology=None,
                 tags=None):
        if parameters is None:
            parameters = {
                'k': 1000 * u.Unit('kJ / (deg**2)'),
                'phi_eq': 180 * u.deg,
                'n': 1 * u.dimensionless
            }
        if independent_variables is None:
            independent_variables = {'phi'}

        super(DihedralType, self).__init__(
            name=name,
            expression=expression,
            parameters=parameters,
            independent_variables=independent_variables,
            topology=topology,
            member_types=member_types,
            set_ref=DIHEDRAL_TYPE_DICT,
            tags=tags
        )
예제 #26
0
    def __init__(
        self,
        name="ImproperType",
        expression=None,
        parameters=None,
        independent_variables=None,
        potential_expression=None,
        member_types=None,
        topology=None,
        tags=None,
    ):
        if potential_expression is None:
            if expression is None:
                expression = "0.5 * k * ((phi - phi_eq))**2"

            if parameters is None:
                parameters = {
                    "k": 1000 * u.Unit("kJ / (deg**2)"),
                    "phi_eq": 0 * u.deg,
                }

            if independent_variables is None:
                independent_variables = {"phi"}

        super(ImproperType, self).__init__(
            name=name,
            expression=expression,
            parameters=parameters,
            independent_variables=independent_variables,
            potential_expression=potential_expression,
            topology=topology,
            member_types=member_types,
            set_ref=IMPROPER_TYPE_DICT,
            tags=tags,
        )
예제 #27
0
 def test_setters(self, charge, mass):
     new_type = AtomType()
     new_type.name = "SettingName"
     new_type.charge = -1.0 * charge
     new_type.mass = 1 * mass
     new_type.independent_variables = 'r'
     new_type.parameters = {'sigma': 1 * u.nm,
                            'epsilon': 10 * u.Unit('kcal / mol')}
     new_type.expression = 'r * sigma * epsilon'
     assert new_type.name == "SettingName"
     assert_allclose_units(new_type.charge, -1.0 * charge, rtol=1e-5, atol=1e-8)
     assert_allclose_units(new_type.mass, 1 * mass, rtol=1e-5, atol=1e-8)
     assert new_type.independent_variables == {sympy.symbols('r')}
     assert new_type.parameters == {'sigma': 1 * u.nm,
                                   'epsilon': 10 * u.Unit('kcal / mol')}
     assert new_type.expression == sympy.sympify('r * sigma * epsilon')
예제 #28
0
    def __init__(self,
                 name='AtomType',
                 mass=0.0 * u.gram / u.mol,
                 charge=0.0 * u.elementary_charge,
                 expression='4*epsilon*((sigma/r)**12 - (sigma/r)**6)',
                 parameters=None,
                 independent_variables=None,
                 atomclass='', doi='', overrides=None, definition='',
                 description='',
                 topology=None):
        if parameters is None:
            parameters = {'sigma': 0.3 * u.nm,
                          'epsilon': 0.3 * u.Unit('kJ')}
        if independent_variables is None:
            independent_variables = {'r'}

        if overrides is None:
            overrides = set()

        super(AtomType, self).__init__(
            name=name,
            expression=expression,
            parameters=parameters,
            independent_variables=independent_variables,
            topology=topology)
        self._mass = _validate_mass(mass)
        self._charge = _validate_charge(charge)
        self._atomclass = _validate_str(atomclass)
        self._doi = _validate_str(doi)
        self._overrides = _validate_set(overrides)
        self._description = _validate_str(description)
        self._definition = _validate_str(definition)
        self._set_ref = ATOM_TYPE_DICT
        self._validate_expression_parameters()
예제 #29
0
    def get_unit(self):

        # Construct unit for this dataset
        units = 1
        for unit, exponent in self.unit_exponents.items():
            if exponent != 0:
                cgs = self.base_units_cgs[unit]
                units *= (base_units[unit]**exponent) * (cgs**exponent)

        # Add cosmological factors
        if self.a_exponent is not None:
            units *= (unyt.Unit('a', registry=self.reg)**self.a_exponent)
        if self.h_exponent is not None:
            units *= (unyt.Unit('h', registry=self.reg)**self.h_exponent)

        return units
예제 #30
0
def _dihedral_types_from_pmd(structure, dihedral_types_member_map=None):
    """Convert ParmEd dihedral types to GMSO DihedralType.

    This function take in a Parmed Structure, iterate through its
    dihedral_types and rb_torsion_types, create a corresponding
    GMSO.DihedralType, and finally return a dictionary containing all
    pairs of pmd.Dihedraltype (or pmd.RBTorsionType) and GMSO.DihedralType

    Parameters
    ----------
    structure: pmd.Structure
        Parmed Structure that needed to be converted.
    dihedral_types_member_map: optional, dict, default=None
        The member types (atomtype string) for each atom associated with the dihedral_types the structure

    Returns
    -------
    pmd_top_dihedraltypes : dict
        A dictionary linking a pmd.DihedralType or pmd.RBTorsionType
        object to its corresponding GMSO.DihedralType object.
    """
    pmd_top_dihedraltypes = dict()
    dihedral_types_member_map = _assert_dict(
        dihedral_types_member_map, "dihedral_types_member_map"
    )

    for dihedraltype in structure.dihedral_types:
        dihedral_params = {
            "k": (dihedraltype.phi_k * u.Unit("kcal / mol")),
            "phi_eq": (dihedraltype.phase * u.degree),
            "n": dihedraltype.per * u.dimensionless,
        }
        member_types = dihedral_types_member_map.get(id(dihedraltype))
        top_dihedraltype = gmso.DihedralType(
            parameters=dihedral_params, member_types=member_types
        )
        pmd_top_dihedraltypes[dihedraltype] = top_dihedraltype

    for dihedraltype in structure.rb_torsion_types:
        dihedral_params = {
            "c0": (dihedraltype.c0 * u.Unit("kcal/mol")),
            "c1": (dihedraltype.c1 * u.Unit("kcal/mol")),
            "c2": (dihedraltype.c2 * u.Unit("kcal/mol")),
            "c3": (dihedraltype.c3 * u.Unit("kcal/mol")),
            "c4": (dihedraltype.c4 * u.Unit("kcal/mol")),
            "c5": (dihedraltype.c5 * u.Unit("kcal/mol")),
        }

        member_types = dihedral_types_member_map.get(id(dihedraltype))

        top_dihedraltype = gmso.DihedralType(
            parameters=dihedral_params,
            expression="c0 * cos(phi)**0 + c1 * cos(phi)**1 + "
            + "c2 * cos(phi)**2 + c3 * cos(phi)**3 + c4 * cos(phi)**4 + "
            + "c5 * cos(phi)**5",
            independent_variables="phi",
            member_types=member_types,
        )
        pmd_top_dihedraltypes[dihedraltype] = top_dihedraltype
    return pmd_top_dihedraltypes