Exemplo n.º 1
0
def test_get_centroid_centroid_direction_vector(tmp_amine4):
    bonder_ids = list(tmp_amine4.get_bonder_ids())
    other_ids = [
        id_ for id_ in range(len(tmp_amine4.atoms))
        if id_ not in bonder_ids
    ]
    coords = tmp_amine4.get_position_matrix()
    for bonder_id in bonder_ids:
        coords[bonder_id] = [10, 0, 0]

    coords[other_ids] = np.zeros((len(other_ids), 3))
    tmp_amine4.set_position_matrix(coords)

    dir_vector = tmp_amine4.get_centroid_centroid_direction_vector()
    assert np.allclose(
        a=stk.normalize_vector(dir_vector),
        b=[-1, 0, 0],
        atol=1e-8
    )

    # Test explicitly setting the fg_ids.
    fg_ids = [0, 2]
    for bonder_id in tmp_amine4.get_bonder_ids(fg_ids=fg_ids):
        coords[bonder_id] = [-100, 0, 0]
    tmp_amine4.set_position_matrix(coords)

    dir_vector = tmp_amine4.get_centroid_centroid_direction_vector(
        fg_ids=fg_ids
    )
    assert np.allclose(
        a=stk.normalize_vector(dir_vector),
        b=[1, 0, 0],
        atol=1e-8
    )
Exemplo n.º 2
0
def _test_with_rotation_to_minimize_angle(molecule):
    """
    Test :meth:`.Molecule.with_rotation_to_minimize_angle`.

    Parameters
    ----------
    molecule : :class:`.Molecule`
        The molecule to test.

    Returns
    -------
    None : :class:`NoneType`

    """

    start = get_displacement_vector(molecule, 0, 1)
    target = get_displacement_vector(molecule, 0, 2)
    new = molecule.with_rotation_to_minimize_angle(
        start=start,
        target=target,
        axis=stk.normalize_vector(np.cross(start, target)),
        origin=next(molecule.get_atomic_positions((0, ))),
    )
    is_clone(new, molecule)

    result = get_displacement_vector(new, 0, 1)
    assert np.allclose(
        a=stk.normalize_vector(result),
        b=stk.normalize_vector(target),
        atol=1e-12,
    )
    assert abs(np.linalg.norm(start) - np.linalg.norm(result)) < 1e-15
Exemplo n.º 3
0
def test_vertex(tmp_four_plus_six, tmp_bromine2):
    host = tmp_four_plus_six
    guest = tmp_bromine2
    atom1, atom2 = guest.get_atom_coords([0, 1])
    guest_start = stk.normalize_vector(atom1 - atom2)
    complex2 = stk.host_guest.Complex(guest_start=guest_start,
                                      guest_target=[1, 1, 1],
                                      displacement=[23, 5, 21])
    complexes = ((stk.host_guest.Complex(), guest_start),
                 (complex2, stk.normalize_vector([1, 1, 1])))
    for complex_, target in complexes:
        v1, v2 = complex_.vertices
        _test_placement(v1, host)
        _test_placement(v2, guest)
        _test_alignment(v2, guest, target)
Exemplo n.º 4
0
def _alignment(vertex, building_block):
    fg_position = building_block.get_centroid(
        atom_ids=building_block.func_groups[0].get_bonder_ids())
    v1 = stk.normalize_vector(fg_position - vertex.get_position())

    def inner(edge):
        v2 = edge.get_position(vertex) - vertex.get_position()
        return v1 @ stk.normalize_vector(v2)

    return inner
Exemplo n.º 5
0
def _test_with_rotation_between_vectors(molecule, target, get_origin):
    """
    Test :meth:`.Molecule.with_rotation_between_vectors`.

    Parameters
    ----------
    molecule : :class:`.Molecule`
        The molecule to test.

    target : :class:`numpy.ndarray`
        The target vector which defines the applied rotation.

    get_origin : :class:`callable`
        Takes a single parameter, `molecule`, and returns a valid
        `origin` parameter for this test. Using a :class:`callable`
        allows the origin for the test to be set to molecule-specific
        values, such as the centroid of the molecule being tested.

    Returns
    -------
    None : :class:`NoneType`

    """

    start = get_displacement_vector(molecule, 0, 1)
    new = molecule.with_rotation_between_vectors(
        start=start,
        target=target,
        origin=get_origin(molecule),
    )
    is_clone(new, molecule)
    result = get_displacement_vector(new, 0, 1)
    assert np.allclose(
        a=stk.normalize_vector(result),
        b=stk.normalize_vector(target),
        atol=1e-12,
    )
    assert abs(np.linalg.norm(start) - np.linalg.norm(result)) < 1e-14
Exemplo n.º 6
0
def test_apply_rotation_between_vectors(tmp_amine2):
    assert not np.allclose(a=next(
        tmp_amine2.get_bonder_direction_vectors())[-1],
                           b=[1, 0, 0],
                           atol=1e-8)

    tmp_amine2.apply_rotation_between_vectors(start=next(
        tmp_amine2.get_bonder_direction_vectors())[-1],
                                              target=[1, 0, 0],
                                              origin=tmp_amine2.get_centroid())
    assert np.allclose(a=stk.normalize_vector(
        next(tmp_amine2.get_bonder_direction_vectors())[-1]),
                       b=[1, 0, 0],
                       atol=1e-8)
Exemplo n.º 7
0
def test_get_direction(tmp_amine2):
    num_atoms = len(tmp_amine2.atoms)
    coords = np.array([[i, 0, 0] for i in range(num_atoms)])
    tmp_amine2.set_position_matrix(coords)

    assert np.allclose(a=tmp_amine2.get_direction(), b=[1, 0, 0], atol=1e-8)

    coords[[1, 3]] = [[1, 1, 1], [3, 3, 3]]
    tmp_amine2.set_position_matrix(coords)

    all_atom_ids = ((1, 3), [1, 3], (i for i in [1, 3]))
    for atom_ids in all_atom_ids:
        assert np.allclose(a=tmp_amine2.get_direction(atom_ids=atom_ids),
                           b=stk.normalize_vector([1, 1, 1]),
                           atol=1e-8)
Exemplo n.º 8
0
def test_get_bonder_direction_vectors(tmp_amine4):
    pos_mat = tmp_amine4.get_position_matrix()
    # Set the coordinate of each bonder to the id of the fg.
    for fg_id, fg in enumerate(tmp_amine4.func_groups):
        for bonder in fg.get_bonder_ids():
            pos_mat[bonder] = [fg_id, fg_id, fg_id]
    tmp_amine4.set_position_matrix(pos_mat)

    dir_vectors = tmp_amine4.get_bonder_direction_vectors()
    for i, (id1, id2, v) in enumerate(dir_vectors):
        # Calculate the expected direction vector based on ids.
        d = stk.normalize_vector(np.array([id2]*3) - np.array([id1]*3))
        assert np.allclose(d, stk.normalize_vector(v), atol=1e-8)
    assert i == 5

    # Test explicitly setting fg_ids.
    dir_vectors = tmp_amine4.get_bonder_direction_vectors(
        fg_ids=[0, 3]
    )
    for i, (id1, id2, v) in enumerate(dir_vectors):
        # Calculate the expected direction vector based on ids.
        d = stk.normalize_vector(np.array([id2]*3) - np.array([id1]*3))
        assert np.allclose(d, stk.normalize_vector(v), atol=1e-8)
    assert i == 0
Exemplo n.º 9
0
def test_centroid_centroid_dir_vector(aldehyde3):
    c1 = aldehyde3.bonder_centroid()
    c2 = aldehyde3.centroid()
    assert np.allclose(stk.normalize_vector(c2 - c1),
                       aldehyde3.centroid_centroid_dir_vector(),
                       atol=1e-8)
Exemplo n.º 10
0
 def inner(edge):
     v2 = edge.get_position(vertex) - vertex.get_position()
     return v1 @ stk.normalize_vector(v2)
Exemplo n.º 11
0
def test_set_orientation2(tmp_aldehyde3):
    tmp_aldehyde3.set_orientation2([1, 2, 3])
    assert np.allclose(tmp_aldehyde3.bonder_plane_normal(),
                       stk.normalize_vector([1, 2, 3]),
                       atol=1e-4)
Exemplo n.º 12
0
def test_set_orientation2(tmp_amine2):
    tmp_amine2.set_orientation2([1, 2, 3], 0)
    vector = next(tmp_amine2.bonder_direction_vectors(0))[-1]
    assert np.allclose(vector, stk.normalize_vector([1, 2, 3]), atol=1e-8)
Exemplo n.º 13
0
 def inner(edge):
     edge_vector = edge.get_position() - vertex.get_position()
     return fg_vector @ stk.normalize_vector(edge_vector)
Exemplo n.º 14
0
def _test_alignment(vertex, bb, target):
    atom1, atom2 = bb.get_atom_coords([0, 1])
    assert np.allclose(a=stk.normalize_vector(atom1 - atom2),
                       b=target,
                       atol=1e-8)