Exemple #1
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()
        )
Exemple #2
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())
Exemple #3
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
Exemple #4
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)
Exemple #5
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)