Пример #1
0
    def test_topology_get_index(self):
        top = Topology()
        conn_members = [Site(), Site(), Site(), Site()]
        for i in range(5):
            top.add_site(Site())
            top.add_connection(Bond(
                connection_members=[conn_members[0], conn_members[1]]))
            top.add_connection(Angle(
                connection_members=[conn_members[0], conn_members[1], conn_members[2]]))
            top.add_connection(Dihedral(
                connection_members=[conn_members[0], conn_members[1], conn_members[2], conn_members[3]]))
            top.add_connection(Improper(
                connection_members=[conn_members[0], conn_members[1], conn_members[2], conn_members[3]]))
        a_bond = Bond(connection_members=[conn_members[0], conn_members[1]])
        an_angle = Angle(connection_members=[conn_members[0], conn_members[1], conn_members[2]])
        a_site = Site()
        a_dihedral = Dihedral(connection_members=[conn_members[0], conn_members[1], conn_members[2], conn_members[3]])
        an_improper = Improper(connection_members=[conn_members[0], conn_members[1], conn_members[2], conn_members[3]])

        top.add_site(a_site)
        top.add_connection(a_bond)
        top.add_connection(an_angle)
        top.add_connection(a_dihedral)
        top.add_connection(an_improper)

        assert top.get_index(a_site) == 9
        assert top.get_index(a_bond) == 5
        assert top.get_index(an_angle) == 5
        assert top.get_index(a_dihedral) == 5
        assert top.get_index(an_improper) == 5
Пример #2
0
    def test_topology_get_index(self):
        top = Topology()
        conn_members = [Atom() for _ in range(10)]
        for atom in conn_members:
            top.add_site(atom)

        for i in range(5):
            top.add_connection(
                Bond(connection_members=[conn_members[i], conn_members[i +
                                                                       1]]))
            top.add_connection(
                Angle(connection_members=[
                    conn_members[i], conn_members[i + 1], conn_members[i + 2]
                ]))
            top.add_connection(
                Dihedral(connection_members=[
                    conn_members[i], conn_members[i + 1], conn_members[i + 2],
                    conn_members[i + 3]
                ]))
            top.add_connection(
                Improper(connection_members=[
                    conn_members[i], conn_members[i + 1], conn_members[i + 2],
                    conn_members[i + 3]
                ]))

        a_atom = Atom()
        a_bond = Bond(connection_members=[conn_members[6], conn_members[7]])
        an_angle = Angle(connection_members=[
            conn_members[6], conn_members[7], conn_members[8]
        ])
        a_dihedral = Dihedral(connection_members=[
            conn_members[6], conn_members[7], conn_members[8], conn_members[9]
        ])
        an_improper = Improper(connection_members=[
            conn_members[6], conn_members[7], conn_members[8], conn_members[9]
        ])

        top.add_site(a_atom)
        top.add_connection(a_bond)
        top.add_connection(an_angle)
        top.add_connection(a_dihedral)
        top.add_connection(an_improper)

        assert top.get_index(a_atom) == 10
        assert top.get_index(a_bond) == 5
        assert top.get_index(an_angle) == 5
        assert top.get_index(a_dihedral) == 5
        assert top.get_index(an_improper) == 5
Пример #3
0
 def test_improper_fake(self):
     site1 = Site(name='site1')
     site2 = Site(name='site2')
     site3 = Site(name='site3')
     site4 = Site(name='site4')
     with pytest.raises(GMSOError):
         Improper(connection_members=['fakesite1', 'fakesite2', 4.2])
Пример #4
0
 def test_improper_fake(self):
     atom1 = Atom(name="atom1")
     atom2 = Atom(name="atom2")
     atom3 = Atom(name="atom3")
     atom4 = Atom(name="atom4")
     with pytest.raises(ValidationError):
         Improper(connection_members=["fakeatom1", "fakeatom2", 4.2])
Пример #5
0
 def test_improper_fake(self):
     atom1 = Atom(name='atom1')
     atom2 = Atom(name='atom2')
     atom3 = Atom(name='atom3')
     atom4 = Atom(name='atom4')
     with pytest.raises(ValidationError):
         Improper(connection_members=['fakeatom1', 'fakeatom2', 4.2])
Пример #6
0
 def test_improper_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"))
     imptype = ImproperType(member_types=[
         atom1.atom_type.name,
         atom2.atom_type.name,
         atom3.atom_type.name,
         atom4.atom_type.name,
     ])
     imp = Improper(connection_members=[atom1, atom2, atom3, atom4], )
     imp.improper_type = imp.connection_type = imptype
     assert "A" in imp.connection_type.member_types
     assert "B" in imp.connection_type.member_types
     assert "C" in imp.connection_type.member_types
     assert "D" in imp.connection_type.member_types
Пример #7
0
 def test_improper_to_json_loop(self, typed_ethane, are_equivalent_atoms):
     for improper in typed_ethane.impropers:
         improper_json = improper.json()
         improper_copy = Improper.parse_raw(improper_json)
         for member1, member2 in zip(improper_copy.connection_members,
                                     improper.connection_members):
             assert are_equivalent_atoms(member1, member2)
         assert improper_copy.improper_type == improper.improper_type
Пример #8
0
    def test_add_equivalent_connections(self):
        atom1 = Atom(name="AtomA")
        atom2 = Atom(name="AtomB")
        atom3 = Atom(name="AtomC")
        atom4 = Atom(name="AtomD")

        improper = Improper(connection_members=[atom1, atom2, atom3, atom4])
        improper_eq = Improper(connection_members=[atom1, atom3, atom2, atom4])
        improper_not_eq = Improper(
            connection_members=[atom2, atom3, atom1, atom4])

        top = Topology()
        top.add_connection(improper)
        top.add_connection(improper_eq)
        assert top.n_impropers == 1
        top.add_connection(improper_not_eq)
        assert top.n_impropers == 2
Пример #9
0
 def test_improper_fake_impropertype(self):
     site1 = Site(name='site1')
     site2 = Site(name='site2')
     site3 = Site(name='site3')
     site4 = Site(name='site4')
     with pytest.raises(GMSOError):
         Improper(connection_members=[site1, site2, site3, site4],
               connection_type='Fake impropertype')
Пример #10
0
 def test_improper_fake_impropertype(self):
     atom1 = Atom(name='atom1')
     atom2 = Atom(name='atom2')
     atom3 = Atom(name='atom3')
     atom4 = Atom(name='atom4')
     with pytest.raises(ValidationError):
         Improper(connection_members=[atom1, atom2, atom3, atom4],
                  connection_type='Fake impropertype')
Пример #11
0
    def test_improper_eq(self):
        atom1 = Atom(name="atom1", position=[0, 0, 0])
        atom2 = Atom(name="atom2", position=[1, 0, 0])
        atom3 = Atom(name="atom3", position=[1, 1, 0])
        atom4 = Atom(name="atom4", position=[1, 1, 1])

        ref_improper = Improper(
            connection_members=[atom1, atom2, atom3, atom4], )

        same_improper = Improper(
            connection_members=[atom1, atom2, atom3, atom4], )

        diff_improper = Improper(
            connection_members=[atom1, atom2, atom3, atom4], )

        assert ref_improper != same_improper
        assert ref_improper != diff_improper
Пример #12
0
    def test_improper_nonparametrized(self):
        atom1 = Atom(name="atom1")
        atom2 = Atom(name="atom2")
        atom3 = Atom(name="atom3")
        atom4 = Atom(name="atom4")

        connect = Improper(connection_members=[atom1, atom2, atom3, atom4])

        assert connect.connection_type is None
Пример #13
0
 def test_improper_fake_impropertype(self):
     atom1 = Atom(name="atom1")
     atom2 = Atom(name="atom2")
     atom3 = Atom(name="atom3")
     atom4 = Atom(name="atom4")
     with pytest.raises(ValidationError):
         Improper(
             connection_members=[atom1, atom2, atom3, atom4],
             connection_type="Fake impropertype",
         )
Пример #14
0
    def test_improper_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_improper = Improper(
            connection_members=[site1, site2, site3, site4],
        )

        same_improper = Improper(
            connection_members=[site1, site2, site3, site4],
        )

        diff_improper = Improper(
            connection_members=[site1, site2, site3, site4],
        )

        assert ref_improper != same_improper
        assert ref_improper != diff_improper
Пример #15
0
    def test_equivalent_members_set(self):
        atom1 = Atom(name="AtomA")
        atom2 = Atom(name="AtomB")
        atom3 = Atom(name="AtomC")
        atom4 = Atom(name="AtomD")

        improper = Improper(connection_members=[atom1, atom2, atom3, atom4])
        improper_eq = Improper(connection_members=[atom1, atom3, atom2, atom4])
        improper_not_eq = Improper(
            connection_members=[atom2, atom3, atom1, atom4])

        assert (tuple(improper_eq.connection_members)
                in improper.equivalent_members())
        assert (tuple(improper.connection_members)
                in improper_eq.equivalent_members())
        assert not (tuple(improper.connection_members)
                    in improper_not_eq.equivalent_members())
Пример #16
0
 def test_improper_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'))
     imptype = ImproperType(member_types=[site1.atom_type.name, 
                                          site2.atom_type.name,
                                          site3.atom_type.name,
                                          site4.atom_type.name])
     imp = Improper(connection_members=[site1, site2, site3, site4], 
             connection_type=imptype)
     assert 'A' in imp.connection_type.member_types
     assert 'B' in imp.connection_type.member_types
     assert 'C' in imp.connection_type.member_types
     assert 'D' in imp.connection_type.member_types
Пример #17
0
    def test_improper_parametrized(self):
        atom1 = Atom(name='atom1')
        atom2 = Atom(name='atom2')
        atom3 = Atom(name='atom3')
        atom4 = Atom(name='atom4')

        improper_type = ImproperType()

        connect = Improper(connection_members=[atom1, atom2, atom3, atom4],
                           improper_type=improper_type,
                           name='improper_name')

        assert len(connect.connection_members) == 4
        assert connect.connection_type is not None
        assert connect.improper_type is not None
        assert connect.name == 'improper_name'
Пример #18
0
    def test_improper_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 = Improper(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
Пример #19
0
    def test_improper_impropertype_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 = ImproperType()
        improper = Improper(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(improper)

        assert top.n_impropers == 1
        assert len(top.improper_types) == 1
        assert len(top.improper_type_expressions) == 1
        assert len(top.atom_type_expressions) == 2
Пример #20
0
    def test_improper_impropertype_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 = ImproperType()
        improper = Improper(connection_members=[atom1, atom2, atom3, atom4],
                            improper_type=atype)
        top.add_site(atom1)
        top.add_site(atom2)
        top.add_site(atom3)
        top.add_site(atom4)
        top.add_connection(improper)

        assert top.n_impropers == 1
        assert len(top.improper_types) == 1
        assert len(top.improper_type_expressions) == 1
        assert len(top.atom_type_expressions) == 2
Пример #21
0
 def test_improper_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'))
     imptype = ImproperType(member_types=[
         atom1.atom_type.name, atom2.atom_type.name, atom3.atom_type.name,
         atom4.atom_type.name
     ])
     imp = Improper(connection_members=[atom1, atom2, atom3, atom4], )
     imp.improper_type = imp.connection_type = imptype
     assert 'A' in imp.connection_type.member_types
     assert 'B' in imp.connection_type.member_types
     assert 'C' in imp.connection_type.member_types
     assert 'D' in imp.connection_type.member_types
Пример #22
0
    def test_improper_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
        improper_type = ImproperType()

        connect = Improper(connection_members=[site1, site2, site3, site4],
                        connection_type=improper_type,
                        name='improper_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 == 'improper_name'