Пример #1
0
    def test_angle(self):
        frame = Frame()
        frame.add_atom(Atom(""), (1, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 1, 0))

        self.assertEqual(frame.angle(0, 1, 2), math.pi / 2.0)
Пример #2
0
    def test_distance(self):
        frame = Frame()
        frame.cell = UnitCell(3.0, 4.0, 5.0)
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (1, 2, 6))

        self.assertEqual(frame.distance(0, 1), math.sqrt(6.0))
Пример #3
0
    def test_distance(self):
        frame = Frame()
        frame.cell = UnitCell(3.0, 4.0, 5.0)
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (1, 2, 6))

        self.assertEqual(frame.distance(0, 1), math.sqrt(6.0))
Пример #4
0
    def test_angle(self):
        frame = Frame()
        frame.add_atom(Atom(""), (1, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 1, 0))

        self.assertEqual(frame.angle(0, 1, 2), math.pi / 2.0)
Пример #5
0
    def test_out_of_plane(self):
        frame = Frame()
        frame.add_atom(Atom(""), (1, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 1, 0))
        frame.add_atom(Atom(""), (0, 0, 3))

        self.assertEqual(frame.out_of_plane(1, 3, 0, 2), 3.0)
Пример #6
0
    def test_out_of_plane(self):
        frame = Frame()
        frame.add_atom(Atom(""), (1, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 1, 0))
        frame.add_atom(Atom(""), (0, 0, 3))

        self.assertEqual(frame.out_of_plane(1, 3, 0, 2), 3.0)
Пример #7
0
    def test_add_atom(self):
        frame = Frame()
        frame.add_atom(Atom("F"), (3, 4, 5))
        self.assertEqual(len(frame.atoms), 1)
        self.assertEqual(list(frame.positions[0]), [3, 4, 5])

        frame.add_velocities()
        frame.add_atom(Atom("F"), (-3, -4, 5), (1, 0, 1))
        self.assertEqual(list(frame.positions[1]), [-3, -4, 5])
        self.assertEqual(list(frame.velocities[1]), [1, 0, 1])
Пример #8
0
    def test_add_atom(self):
        frame = Frame()
        frame.add_atom(Atom("F"), (3, 4, 5))
        self.assertEqual(len(frame.atoms), 1)
        self.assertEqual(list(frame.positions[0]), [3, 4, 5])

        frame.add_velocities()
        frame.add_atom(Atom("F"), (-3, -4, 5), (1, 0, 1))
        self.assertEqual(list(frame.positions[1]), [-3, -4, 5])
        self.assertEqual(list(frame.velocities[1]), [1, 0, 1])
Пример #9
0
    def test_indexes(self):
        # Create an input file
        frame = Frame()
        for i in range(120):
            frame.add_atom(Atom('X'), [i % 10, i + 1 % 10, i + 2 % 10])

        with Trajectory("filename.xyz", "w") as file:
            file.write(frame)

        path = os.path.join(ROOT, "..", "examples", "indexes.py")
        # disable output
        exec(open(path).read(), globals(), {'print': lambda _: None})
Пример #10
0
def testing_frame():
    frame = Frame()

    frame.add_atom(Atom("H"), [0, 0, 0])
    frame.add_atom(Atom("O"), [0, 0, 0])
    frame.add_atom(Atom("O"), [0, 0, 0])
    frame.add_atom(Atom("H"), [0, 0, 0])

    frame.add_bond(0, 1)
    frame.add_bond(1, 2)
    frame.add_bond(2, 3)

    return frame
Пример #11
0
    def test_select(self):
        # Create an input file
        frame = Frame()
        NAMES = ["N", "Zn", "C", "O"]
        for i in range(120):
            frame.add_atom(Atom(NAMES[i % 4]),
                           [i % 10, i + 1 % 10, i + 2 % 10])

        with Trajectory("input.arc", "w") as file:
            file.write(frame)

        path = os.path.join(ROOT, "..", "examples", "select.py")
        exec(open(path).read(), globals())
Пример #12
0
    def test_write(self):
        frame = Frame()
        for i in range(4):
            frame.add_atom(Atom("X"), [1, 2, 3])

        with Trajectory("test-tmp.xyz", "w") as fd:
            fd.write(frame)

        expected_content = """4
Written by the chemfiles library
X 1 2 3
X 1 2 3
X 1 2 3
X 1 2 3
"""
        with open("test-tmp.xyz") as fd:
            self.assertEqual(fd.read(), expected_content)

        os.unlink("test-tmp.xyz")
Пример #13
0
    def test_write(self):
        frame = Frame()
        for i in range(4):
            frame.add_atom(Atom("X"), [1, 2, 3])

        with Trajectory("test-tmp.xyz", "w") as fd:
            fd.write(frame)

        expected_content = """4
Written by the chemfiles library
X 1 2 3
X 1 2 3
X 1 2 3
X 1 2 3
"""
        with open("test-tmp.xyz") as fd:
            self.assertEqual(fd.read(), expected_content)

        os.unlink("test-tmp.xyz")
Пример #14
0
    def test_bonds(self):
        frame = Frame()
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))

        frame.add_bond(0, 1)
        frame.add_bond(3, 4)
        frame.add_bond(2, 1, BondOrder.Qintuplet)

        self.assertEqual(
            frame.topology.bonds.all(), np.array([[0, 1], [1, 2], [3, 4]]).all()
        )

        self.assertEqual(
            frame.topology.bonds_orders,
            [BondOrder.Unknown, BondOrder.Qintuplet, BondOrder.Unknown]
        )

        frame.remove_bond(3, 4)
        # Also try to remove non-existing bonds
        frame.remove_bond(3, 4)
        frame.remove_bond(0, 4)

        self.assertEqual(
            frame.topology.bonds.all(), np.array([[0, 1], [1, 2]]).all()
        )
Пример #15
0
    def test_bonds(self):
        frame = Frame()
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))

        frame.add_bond(0, 1)
        frame.add_bond(3, 4)
        frame.add_bond(2, 1, BondOrder.Qintuplet)

        self.assertEqual(frame.topology.bonds.all(),
                         np.array([[0, 1], [1, 2], [3, 4]]).all())

        self.assertEqual(
            frame.topology.bonds_orders,
            [BondOrder.Unknown, BondOrder.Qintuplet, BondOrder.Unknown])

        frame.remove_bond(3, 4)
        # Also try to remove non-existing bonds
        frame.remove_bond(3, 4)
        frame.remove_bond(0, 4)

        self.assertEqual(frame.topology.bonds.all(),
                         np.array([[0, 1], [1, 2]]).all())
Пример #16
0
    def test_dihedral(self):
        frame = Frame()
        frame.add_atom(Atom(""), (1, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 1, 0))
        frame.add_atom(Atom(""), (-1, 1, 0))

        self.assertEqual(frame.dihedral(0, 1, 2, 3), math.pi)
Пример #17
0
    def test_dihedral(self):
        frame = Frame()
        frame.add_atom(Atom(""), (1, 0, 0))
        frame.add_atom(Atom(""), (0, 0, 0))
        frame.add_atom(Atom(""), (0, 1, 0))
        frame.add_atom(Atom(""), (-1, 1, 0))

        self.assertEqual(frame.dihedral(0, 1, 2, 3), math.pi)
Пример #18
0
import numpy as np
from chemfiles import Topology, Frame, Atom, UnitCell, Trajectory

topology = Topology()
topology.add_atom(Atom("H"))
topology.add_atom(Atom("O"))
topology.add_atom(Atom("H"))

topology.add_bond(0, 1)
topology.add_bond(2, 1)

frame = Frame()
frame.resize(3)
frame.set_topology(topology)

positions = frame.positions()
positions[0, :] = np.array([1.0, 0.0, 0.0])
positions[1, :] = np.array([0.0, 0.0, 0.0])
positions[2, :] = np.array([0.0, 1.0, 0.0])

frame.add_atom(Atom("O"), [5.0, 0.0, 0.0])
frame.add_atom(Atom("C"), [6.0, 0.0, 0.0])
frame.add_atom(Atom("O"), [7.0, 0.0, 0.0])
frame.add_bond(3, 4)
frame.add_bond(4, 5)

frame.set_cell(UnitCell(10, 10, 10))

trajectory = Trajectory("water-co2.pdb", 'w')
trajectory.write(frame)
Пример #19
0
#!/usr/bin/env python
import numpy as np
from chemfiles import Topology, Frame, Atom, UnitCell, Trajectory

topology = Topology()
topology.atoms.append(Atom("H"))
topology.atoms.append(Atom("O"))
topology.atoms.append(Atom("H"))

topology.add_bond(0, 1)
topology.add_bond(2, 1)

frame = Frame()
frame.resize(3)
frame.topology = topology

frame.positions[0, :] = np.array([1.0, 0.0, 0.0])
frame.positions[1, :] = np.array([0.0, 0.0, 0.0])
frame.positions[2, :] = np.array([0.0, 1.0, 0.0])

frame.add_atom(Atom("O"), [5.0, 0.0, 0.0])
frame.add_atom(Atom("C"), [6.0, 0.0, 0.0])
frame.add_atom(Atom("O"), [7.0, 0.0, 0.0])
frame.add_bond(3, 4)
frame.add_bond(4, 5)

frame.cell = UnitCell(10, 10, 10)

with Trajectory("water-co2.pdb", 'w') as trajectory:
    trajectory.write(frame)
Пример #20
0
                    if state < 7:
                        x1, y1, x2, y2, x3, y3, z3 = coordinate_si(
                            ring, column, state)
                    if state > 6 and ring % 4 == 1 and column % 2 == 0:  #up (vert)
                        x1, y1, x2, y2, x3, y3, z3 = coordinate_up(
                            ring, column, state)
                    if state > 6 and ring % 4 == 1 and column % 2 == 1:  #down (rouge)
                        x1, y1, x2, y2, x3, y3, z3 = coordinate_down(
                            ring, column, state)
                    if state > 6 and ring % 4 == 3 and column % 2 == 1:  #up (vert)
                        x1, y1, x2, y2, x3, y3, z3 = coordinate_up(
                            ring, column, state)
                    if state > 6 and ring % 4 == 3 and column % 2 == 0:  #down (rouge)
                        x1, y1, x2, y2, x3, y3, z3 = coordinate_down(
                            ring, column, state)
                    if state < 7 and state > 0:
                        atom1 = Atom("Si", "Si")
                        atom2 = Atom("O", "O")
                        atom3 = Atom("H", "H")
                        frame.add_atom(atom1, [x1, y1, 0])
                        frame.add_atom(atom2, [x2, y2, height])
                        frame.add_atom(atom3, [x3, y3, height])
                    if state > 7:
                        atom1 = Atom("Ow", "O")
                        atom2 = Atom("Hw", "H")
                        atom3 = Atom("Hw", "H")
                        frame.add_atom(atom1, [x1, y1, height])
                        frame.add_atom(atom2, [x2, y2, height])
                        frame.add_atom(atom3, [x3, y3, z3])
                ring += 1