Пример #1
0
def test_atom():

    h = Atom(atomic_symbol='H', x=0.0, y=0.0, z=0.0)
    assert h.label == 'H'
    assert type(h.coord) == np.ndarray
    assert len(h.coord) == 3
    assert h.coord[0] == 0
    assert h.coord[1] == 0
    assert h.coord[2] == 0

    # Translate the H atom by 1 A in the z direction
    h.translate(vec=np.array([0.0, 0.0, 1.0]))
    assert np.linalg.norm(h.coord - np.array([0.0, 0.0, 1.0])) < 1E-6

    # Rotate the atom 180° (pi radians) in the x axis
    h.rotate(axis=np.array([1.0, 0.0, 0.0]), theta=np.pi)
    assert np.linalg.norm(h.coord - np.array([0.0, 0.0, -1.0])) < 1E-6

    # Perform a rotation about a different origin e.g. (1, 0, -1)
    h.rotate(axis=np.array([0.0, 0.0, 1.0]),
             theta=np.pi,
             origin=np.array([1.0, 0.0, -1.0]))
    assert np.linalg.norm(h.coord - np.array([2.0, 0.0, -1.0])) < 1E-6

    # Ensure that the atoms has a string representation
    assert len(str(h)) > 0
Пример #2
0
def get_h2o(r1, r2, r3):
    """
            O
      r1  /   \  r2
         H     H
           r3
    """
    theta = np.arccos(max((r2**2 + r1**2 - r3**2) / (2 * r2 * r1), -1))
    h_b = Atom('H', x=r2, y=0.0, z=0.0)
    # Rotate in the z axis
    h_b.rotate(axis=np.array([0.0, 0.0, 1.0]), theta=theta)

    config = gt.Configuration(charge=0, mult=1, box=gt.Box([10, 10, 10]))
    config.set_atoms(atoms=[Atom('O'), Atom('H', x=r1), h_b])
    return config