示例#1
0
 def test_dihedral_types_to_json_loop(self, typed_ethane):
     dihedral_types_to_test = typed_ethane.dihedral_types
     for dihedral_type in dihedral_types_to_test:
         dihedral_type_json = dihedral_type.json()
         dihedral_type_copy = DihedralType.parse_raw(dihedral_type_json)
         dihedral_type_copy.topology = dihedral_type.topology
         assert dihedral_type_copy == dihedral_type
    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)
示例#3
0
 def test_dihedral_constituent_types(self):
     atom1 = Atom(name="atom1",
                  position=[0, 0, 0],
                  atom_type=AtomType(name="A"))
     atom2 = Atom(name="atom2",
                  position=[1, 0, 0],
                  atom_type=AtomType(name="B"))
     atom3 = Atom(name="atom3",
                  position=[1, 1, 0],
                  atom_type=AtomType(name="C"))
     atom4 = Atom(name="atom4",
                  position=[1, 1, 4],
                  atom_type=AtomType(name="D"))
     dihtype = DihedralType(member_types=[
         atom1.atom_type.name,
         atom2.atom_type.name,
         atom3.atom_type.name,
         atom4.atom_type.name,
     ])
     dih = Dihedral(connection_members=[atom1, atom2, atom3, atom4], )
     dih.dihedral_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_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()])
示例#5
0
    def test_ryckaert_to_opls(self, templates):

        # Pick some RB parameters at random
        params = {
            "c0": 1.53 * u.Unit("kJ/mol"),
            "c1": 0.76 * u.Unit("kJ/mol"),
            "c2": -0.22 * u.Unit("kJ/mol"),
            "c3": 3.55 * u.Unit("kJ/mol"),
            "c4": 0.94 * u.Unit("kJ/mol"),
            "c5": 0.0 * u.Unit("kJ/mol"),
        }

        ryckaert_bellemans_torsion_potential = templates[
            "RyckaertBellemansTorsionPotential"]

        name = ryckaert_bellemans_torsion_potential.name
        expression = ryckaert_bellemans_torsion_potential.expression
        variables = ryckaert_bellemans_torsion_potential.independent_variables

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

        # Convert connection to OPLS
        opls_connection_type = convert_ryckaert_to_opls(
            ryckaert_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()
                    ])),
            )
    def test_ryckaert_to_opls(self, templates):

        # Pick some RB parameters at random
        params = {
            'c0': 1.53 * u.Unit('kJ/mol'),
            'c1': 0.76 * u.Unit('kJ/mol'),
            'c2': -0.22 * u.Unit('kJ/mol'),
            'c3': 3.55 * u.Unit('kJ/mol'),
            'c4': 0.94 * u.Unit('kJ/mol'),
            'c5': 0.0 * u.Unit('kJ/mol')
        }

        ryckaert_bellemans_torsion_potential = templates[
            'RyckaertBellemansTorsionPotential']

        name = ryckaert_bellemans_torsion_potential.name
        expression = ryckaert_bellemans_torsion_potential.expression
        variables = ryckaert_bellemans_torsion_potential.independent_variables

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

        # Convert connection to OPLS
        opls_connection_type = convert_ryckaert_to_opls(
            ryckaert_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()
                    ])),
            )
示例#7
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()
                    ])),
            )
示例#8
0
    def test_dihedral_parametrized(self):
        atom1 = Atom(name='atom1')
        atom2 = Atom(name='atom2')
        atom3 = Atom(name='atom3')
        atom4 = Atom(name='atom4')

        dihedral_type = DihedralType()

        connect = Dihedral(connection_members=[atom1, atom2, atom3, atom4],
                           dihedral_type=dihedral_type,
                           name='dihedral_name')

        assert len(connect.connection_members) == 4
        assert connect.connection_type is not None
        assert connect.dihedral_type is not None
        assert connect.name == 'dihedral_name'
    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()
                    ])),
            )
示例#10
0
    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_dihedrals == 1
        assert len(top.dihedral_types) == 1
        assert len(top.dihedral_type_expressions) == 1
        assert len(top.atom_type_expressions) == 2
示例#11
0
    def test_dihedral_dihedraltype_update(self):
        top = Topology()

        atype1 = AtomType(expression='sigma + epsilon*r')
        atype2 = AtomType(expression='sigma * epsilon*r')
        atom1 = Atom(name='a', atom_type=atype1)
        atom2 = Atom(name='b', atom_type=atype2)
        atom3 = Atom(name='c', atom_type=atype2)
        atom4 = Atom(name='d', atom_type=atype1)
        atype = DihedralType()
        dihedral = Dihedral(connection_members=[atom1, atom2, atom3, atom4],
                            dihedral_type=atype)
        top.add_site(atom1)
        top.add_site(atom2)
        top.add_site(atom3)
        top.add_site(atom4)
        top.add_connection(dihedral)

        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
示例#12
0
 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
示例#13
0
    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,
                           name='dihedral_name')

        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
        assert connect.name == 'dihedral_name'
示例#14
0
 def test_dihedral_constituent_types(self):
     atom1 = Atom(name='atom1',
                  position=[0, 0, 0],
                  atom_type=AtomType(name='A'))
     atom2 = Atom(name='atom2',
                  position=[1, 0, 0],
                  atom_type=AtomType(name='B'))
     atom3 = Atom(name='atom3',
                  position=[1, 1, 0],
                  atom_type=AtomType(name='C'))
     atom4 = Atom(name='atom4',
                  position=[1, 1, 4],
                  atom_type=AtomType(name='D'))
     dihtype = DihedralType(member_types=[
         atom1.atom_type.name, atom2.atom_type.name, atom3.atom_type.name,
         atom4.atom_type.name
     ])
     dih = Dihedral(connection_members=[atom1, atom2, atom3, atom4], )
     dih.dihedral_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_invalid_connection_type(self, templates):
        params = {
            'c0': 1.53 * u.Unit('kJ/mol'),
            'c1': 0.76 * u.Unit('kJ/mol'),
            'c2': -0.22 * u.Unit('kJ/mol'),
            'c3': 3.55 * u.Unit('kJ/mol'),
            'c4': 0.94 * u.Unit('kJ/mol'),
            'c5': 0.0 * u.Unit('kJ/mol')
        }
        ryckaert_bellemans_torsion_potential = templates[
            'RyckaertBellemansTorsionPotential']

        name = ryckaert_bellemans_torsion_potential.name
        expression = ryckaert_bellemans_torsion_potential.expression
        variables = ['phi', 'psi']

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

        with pytest.raises(GMSOError, match='Cannot use'):
            opls_connection_type = convert_ryckaert_to_opls(
                ryckaert_connection_type)

        expression = 'c0+c1+c2+c3+c4+c5+phi'
        variables = ryckaert_bellemans_torsion_potential.independent_variables
        ryckaert_connection_type = DihedralType(
            name=name,
            expression=expression,
            independent_variables=variables,
            parameters=params)

        with pytest.raises(GMSOError, match='Cannot use'):
            opls_connection_type = convert_ryckaert_to_opls(
                ryckaert_connection_type)

        # 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 = ['phi', 'psi']

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

        with pytest.raises(GMSOError, match=''):
            ryckaert_connection_type = convert_opls_to_ryckaert(
                opls_connection_type)

        variables = opls_torsion_potential.independent_variables
        expression = 'k0+k1+k2+k3+k4+phi'
        opls_connection_type = DihedralType(name=name,
                                            expression=expression,
                                            independent_variables=variables,
                                            parameters=params)

        with pytest.raises(GMSOError, match=''):
            ryckaert_connection_type = convert_opls_to_ryckaert(
                opls_connection_type)
示例#16
0
    def test_invalid_connection_type(self, templates):
        params = {
            "c0": 1.53 * u.Unit("kJ/mol"),
            "c1": 0.76 * u.Unit("kJ/mol"),
            "c2": -0.22 * u.Unit("kJ/mol"),
            "c3": 3.55 * u.Unit("kJ/mol"),
            "c4": 0.94 * u.Unit("kJ/mol"),
            "c5": 0.0 * u.Unit("kJ/mol"),
        }
        ryckaert_bellemans_torsion_potential = templates[
            "RyckaertBellemansTorsionPotential"]

        name = ryckaert_bellemans_torsion_potential.name
        expression = (str(ryckaert_bellemans_torsion_potential.expression) +
                      " + 3 * psi")
        variables = ["phi", "psi"]

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

        with pytest.raises(GMSOError, match="Cannot use"):
            opls_connection_type = convert_ryckaert_to_opls(
                ryckaert_connection_type)

        expression = "c0+c1+c2+c3+c4+c5+phi"
        variables = ryckaert_bellemans_torsion_potential.independent_variables
        ryckaert_connection_type = DihedralType(
            name=name,
            expression=expression,
            independent_variables=variables,
            parameters=params,
        )

        with pytest.raises(GMSOError, match="Cannot use"):
            opls_connection_type = convert_ryckaert_to_opls(
                ryckaert_connection_type)

        # 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 = (str(opls_torsion_potential.expression) +
                      " + 0.5 * k1 * (1 + cos(psi))")
        variables = ["phi", "psi"]

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

        with pytest.raises(GMSOError, match=""):
            ryckaert_connection_type = convert_opls_to_ryckaert(
                opls_connection_type)

        variables = opls_torsion_potential.independent_variables
        expression = "k0+k1+k2+k3+k4+phi"
        opls_connection_type = DihedralType(
            name=name,
            expression=expression,
            independent_variables=variables,
            parameters=params,
        )

        with pytest.raises(GMSOError, match=""):
            ryckaert_connection_type = convert_opls_to_ryckaert(
                opls_connection_type)