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_square(self): mytop = Topology() s1 = Atom(name="1") s2 = Atom(name="2") s3 = Atom(name="3") s4 = Atom(name="4") c12 = Bond(connection_members=[s1, s2]) c23 = Bond(connection_members=[s2, s3]) c34 = Bond(connection_members=[s3, s4]) c41 = Bond(connection_members=[s4, s1]) for site in [s1, s2, s3, s4]: mytop.add_site(site, update_types=False) for conn in [c12, c23, c34, c41]: mytop.add_connection(conn, update_types=False) assert mytop.n_bonds == 4 assert mytop.n_angles == 0 assert mytop.n_dihedrals == 0 assert mytop.n_impropers == 0 mytop.identify_connections() assert mytop.n_bonds == 4 assert mytop.n_angles == 4 assert mytop.n_dihedrals == 4 assert mytop.n_impropers == 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
def test_angle_fake_angletype(self): atom1 = Atom(name='atom1') atom2 = Atom(name='atom2') atom3 = Atom(name='atom3') with pytest.raises(ValidationError): Angle(connection_members=[atom1, atom2, atom3], angle_type='Fake angletype')
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_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])
def test_angle_nonparametrized(self): atom1 = Atom(name='atom1') atom2 = Atom(name='atom2') atom3 = Atom(name='atom3') connect = Angle(connection_members=[atom1, atom2, atom3]) assert connect.angle_type is None
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_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])
def test_bond_nonparametrized(self): atom1 = Atom(name='atom1') atom2 = Atom(name='atom2') connect = Bond(connection_members=[atom1, atom2]) assert connect.bond_type is None
def test_square_with_bridge(self): mytop = Topology() s1 = Atom(name="1") s2 = Atom(name="2") s3 = Atom(name="3") s4 = Atom(name="4") c12 = Bond(connection_members=[s1, s2]) c23 = Bond(connection_members=[s2, s3]) c34 = Bond(connection_members=[s3, s4]) c41 = Bond(connection_members=[s4, s1]) c24 = Bond(connection_members=[s2, s4]) mytop.add_site(s1, update_types=False) mytop.add_site(s2, update_types=False) mytop.add_site(s3, update_types=False) mytop.add_site(s4, update_types=False) mytop.add_connection(c12, update_types=False) mytop.add_connection(c23, update_types=False) mytop.add_connection(c34, update_types=False) mytop.add_connection(c41, update_types=False) mytop.add_connection(c24, update_types=False) assert mytop.n_bonds == 5 assert mytop.n_angles == 0 assert mytop.n_dihedrals == 0 assert mytop.n_impropers == 0 mytop.identify_connections() assert mytop.n_bonds == 5 assert mytop.n_angles == 8 assert mytop.n_dihedrals == 6 assert mytop.n_impropers == 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_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')
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_equivalent_members_set(self): atom1 = Atom(name="AtomA") atom2 = Atom(name="AtomB") bond = Bond(connection_members=[atom1, atom2]) bond_eq = Bond(connection_members=[atom2, atom1]) assert (tuple(bond_eq.connection_members) in bond.equivalent_members()) assert (tuple(bond.connection_members) in bond_eq.equivalent_members())
def test_equivalence(self): ref = Atom(name="atom", position=u.nm * np.zeros(3)) same_atom = Atom(name="atom", position=u.nm * np.zeros(3)) other_pos = Atom(name="atom", position=u.nm * np.ones(3)) other_name = Atom(name="atom", position=u.nm * np.ones(3)) # Two sites are never equivalent assert ref != same_atom assert ref != other_pos assert ref != other_name
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
def test_angle_fake_angletype(self): atom1 = Atom(name="atom1") atom2 = Atom(name="atom2") atom3 = Atom(name="atom3") with pytest.raises(ValidationError): Angle( connection_members=[atom1, atom2, atom3], angle_type="Fake angletype", )
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_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", )
def test_add_equivalent_connections(self): atom1 = Atom(name="AtomA") atom2 = Atom(name="AtomB") bond = Bond(connection_members=[atom1, atom2]) bond_eq = Bond(connection_members=[atom2, atom1]) top = Topology() top.add_connection(bond) top.add_connection(bond_eq) assert top.n_bonds == 1
def test_add_duplicate_connected_atom(self): top = Topology() atom1 = Atom(name="AtomA") atom2 = Atom(name="AtomB") bond = Bond(connection_members=[atom1, atom2]) bond_eq = Bond(connection_members=[atom1, atom2]) top.add_connection(bond) top.add_connection(bond_eq) top.update_topology() assert top.n_connections == 1
def test_add_connection(self): top = Topology() atom1 = Atom(name='atom1') atom2 = Atom(name='atom2') connect = Bond(connection_members=[atom1, atom2]) top.add_connection(connect) top.add_site(atom1) top.add_site(atom2) assert len(top.connections) == 1
def test_bond_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')) bondtype = BondType( member_types=[atom1.atom_type.name, atom2.atom_type.name]) bond = Bond(connection_members=[atom1, atom2], bond_type=bondtype) assert 'A' in bond.connection_type.member_types assert 'B' in bond.connection_type.member_types
def test_bond_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")) bondtype = BondType( member_types=[atom1.atom_type.name, atom2.atom_type.name]) bond = Bond(connection_members=[atom1, atom2], bond_type=bondtype) assert "A" in bond.connection_type.member_types assert "B" in bond.connection_type.member_types
def test_bond_eq(self): atom1 = Atom(name='atom1', position=[0, 0, 0]) atom2 = Atom(name='atom2', position=[1, 1, 1]) ref_connection = Bond(connection_members=[atom1, atom2], ) same_connection = Bond(connection_members=[atom1, atom2], ) diff_connection = Bond(connection_members=[atom1, atom2], ) assert ref_connection != same_connection assert ref_connection != diff_connection
def test_bond_parametrized(self): atom1 = Atom(name='atom1') atom2 = Atom(name='atom2') bond_type = BondType() connect = Bond(connection_members=[atom1, atom2], bond_type=bond_type, name='bond_name') assert len(connect.connection_members) == 2 assert connect.connection_type is not None assert connect.name == 'bond_name'
def test_atom_type_with_topology_and_site_change_properties(self): site1 = Atom() site2 = Atom() top = Topology() atom_type1 = AtomType() atom_type2 = AtomType() site1.atom_type = atom_type1 site2.atom_type = atom_type2 top.add_site(site1) top.add_site(site2) site1.atom_type.mass = 250 assert site2.atom_type.mass == 250 assert top.atom_types[0].mass == 250
def test_angle_eq(self): atom1 = Atom(name='atom1', position=[0, 0, 0]) atom2 = Atom(name='atom2', position=[1, 1, 1]) atom3 = Atom(name='atom3', position=[1, 1, 1]) ref_angle = Angle(connection_members=[atom1, atom2, atom3], ) same_angle = Angle(connection_members=[atom1, atom2, atom3], ) diff_angle = Angle(connection_members=[atom3, atom2, atom1], ) assert ref_angle != same_angle assert ref_angle != diff_angle
def test_equivalent_members_set(self): atom1 = Atom(name="AtomA") atom2 = Atom(name="AtomB") atom3 = Atom(name="AtomC") angle = Angle(connection_members=[atom1, atom2, atom3]) angle_eq = Angle(connection_members=[atom3, atom2, atom1]) angle_not_eq = Angle(connection_members=[atom1, atom3, atom2]) assert tuple(angle_eq.connection_members) in angle.equivalent_members() assert tuple(angle.connection_members) in angle_eq.equivalent_members() assert not (tuple(angle.connection_members) in angle_not_eq.equivalent_members())