def test_atom_invalid_position(self): atom = Atom(name='invalidSite') with pytest.raises(ValueError) as e: atom.position = [0, 0, 0, 0] assert 'Position of shape (3,) is not valid. ' \ 'Accepted values: (a.) 3-tuple, (b.) list of length 3 ' \ '(c.) np.array or unyt.unyt_array of shape (3,)' in e
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_set_with_atom_type(self): lithium_type = AtomType(mass=6.941, charge=1) atom = Atom(name="Lithium") atom.atom_type = lithium_type assert atom.charge == 1 * u.elementary_charge assert atom.mass == 6.941 * u.gram / u.mol
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_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_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 _get_atoms(filename, topology, unit_style, type_list): """Parse the atom information in the LAMMPS data file.""" with open(filename, "r") as lammps_file: for i, line in enumerate(lammps_file): if "atoms" in line.split(): n_atoms = int(line.split()[0]) if "Atoms" in line.split(): break atom_lines = open(filename, "r").readlines()[i + 2:i + n_atoms + 2] for line in atom_lines: atom_line = line.split() atom_type = atom_line[2] charge = u.unyt_quantity(float(atom_line[3]), get_units(unit_style)["charge"]) coord = u.angstrom * u.unyt_array( [float(atom_line[4]), float(atom_line[5]), float(atom_line[6])]) site = Atom( charge=charge, position=coord, atom_type=type_list[int(atom_type) - 1], ) element = element_by_mass(site.atom_type.mass.value) site.name = element.name site.element = element topology.add_site(site) topology.update_sites() return topology
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_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_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_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_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_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_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_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_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_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_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_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_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_with_1000_atom_types(self): top = Topology() for i in range(1000): site = Atom() atom_type = AtomType() site.atom_type = atom_type top.add_site(site, update_types=False) top.update_topology() assert len(top.atom_types) == 1 assert top.n_sites == 1000
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