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
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
def test_dihedral_fake(self): atom1 = Atom(name="atom1") atom2 = Atom(name="atom2") atom3 = Atom(name="atom3") atom4 = Atom(name="atom4") with pytest.raises(ValidationError): Dihedral(connection_members=["fakeatom1", "fakeatom2", 4.2])
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_dihedral_fake(self): site1 = Site(name='site1') site2 = Site(name='site2') site3 = Site(name='site3') site4 = Site(name='site4') with pytest.raises(GMSOError): Dihedral(connection_members=['fakesite1', 'fakesite2', 4.2])
def test_dihedral_fake(self): atom1 = Atom(name='atom1') atom2 = Atom(name='atom2') atom3 = Atom(name='atom3') atom4 = Atom(name='atom4') with pytest.raises(ValidationError): Dihedral(connection_members=['fakeatom1', 'fakeatom2', 4.2])
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, site3, site4], ) assert ref_dihedral != same_dihedral assert ref_dihedral != diff_dihedral
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(GMSOError): Dihedral(connection_members=[site1, site2, site3, site4], connection_type='Fake dihedraltype')
def test_dihedral_fake_dihedraltype(self): atom1 = Atom(name='atom1') atom2 = Atom(name='atom2') atom3 = Atom(name='atom3') atom4 = Atom(name='atom4') with pytest.raises(ValidationError): Dihedral(connection_members=[atom1, atom2, atom3, atom4], dihedral_type='Fake dihedraltype')
def test_equivalent_members_set(self): atom1 = Atom(name="AtomA") atom2 = Atom(name="AtomB") atom3 = Atom(name="AtomC") atom4 = Atom(name="AtomD") dihedral = Dihedral(connection_members=[atom1, atom2, atom3, atom4]) dihedral_eq = Dihedral(connection_members=[atom4, atom3, atom2, atom1]) dihedral_not_eq = Dihedral( connection_members=[atom4, atom2, atom3, atom1]) assert (tuple(dihedral_eq.connection_members) in dihedral.equivalent_members()) assert (tuple(dihedral.connection_members) in dihedral_eq.equivalent_members()) assert not (tuple(dihedral.connection_members) in dihedral_not_eq.equivalent_members())
def test_dihedral_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_dihedral = Dihedral( connection_members=[atom1, atom2, atom3, atom4], ) same_dihedral = Dihedral( connection_members=[atom1, atom2, atom3, atom4], ) diff_dihedral = Dihedral( connection_members=[atom1, atom2, atom3, atom4], ) assert ref_dihedral != same_dihedral assert ref_dihedral != diff_dihedral
def test_dihedral_nonparametrized(self): atom1 = Atom(name="atom1") atom2 = Atom(name="atom1") atom3 = Atom(name="atom3") atom4 = Atom(name="atom4") connect = Dihedral(connection_members=[atom1, atom2, atom3, atom4]) assert connect.connection_type is None
def test_add_equivalent_connections(self): atom1 = Atom(name="AtomA") atom2 = Atom(name="AtomB") atom3 = Atom(name="AtomC") atom4 = Atom(name="AtomD") dihedral = Dihedral(connection_members=[atom1, atom2, atom3, atom4]) dihedral_eq = Dihedral(connection_members=[atom4, atom3, atom2, atom1]) dihedral_not_eq = Dihedral( connection_members=[atom4, atom2, atom3, atom1]) top = Topology() top.add_connection(dihedral) top.add_connection(dihedral_eq) assert top.n_dihedrals == 1 top.add_connection(dihedral_not_eq) assert top.n_dihedrals == 2
def test_dihedral_fake_dihedraltype(self): atom1 = Atom(name="atom1") atom2 = Atom(name="atom2") atom3 = Atom(name="atom3") atom4 = Atom(name="atom4") with pytest.raises(ValidationError): Dihedral( connection_members=[atom1, atom2, atom3, atom4], dihedral_type="Fake dihedraltype", )
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_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_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
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
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_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_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'