Exemplo n.º 1
0
def test_c_get_result(collapser, coll_molecule, coll_final_position_matrix):
    original_pos_mat = coll_molecule.get_position_matrix()
    subunits = coll_molecule.get_subunits(bond_pair_ids=((0, 3), ))
    test_mol, results = collapser.get_result(
        mol=coll_molecule,
        bond_pair_ids=((0, 3), ),
        subunits=subunits,
    )

    final_min_distance = min(
        dist for dist in collapser._get_subunit_distances(test_mol, subunits))
    # Give it some wiggle room.
    assert np.isclose(1.4947505, final_min_distance, atol=1E-8)

    # Check position matrix because this code is deterministic.
    test_pos_mat = test_mol.get_position_matrix()
    for i in range(len(coll_final_position_matrix)):
        test = test_pos_mat[i]
        given = coll_final_position_matrix[i]
        assert np.all(np.isclose(test, given, atol=1E-8))

    # Test all other bond lengths are equivalent.
    for bond in coll_molecule.get_bonds():
        if (bond.get_atom1_id(), bond.get_atom2_id()) != (0, 3):
            test = get_atom_distance(
                position_matrix=results.get_position_matrix(),
                atom1_id=bond.get_atom1_id(),
                atom2_id=bond.get_atom2_id(),
            )
            bond_length = get_atom_distance(
                position_matrix=original_pos_mat,
                atom1_id=bond.get_atom1_id(),
                atom2_id=bond.get_atom2_id(),
            )
            assert np.isclose(test, bond_length, atol=1E-6)
Exemplo n.º 2
0
def test_opt_get_result(optimizer, molecule):
    original_pos_mat = molecule.get_position_matrix()
    subunits = molecule.get_subunits(bond_pair_ids=((0, 3), ))
    mol, results = optimizer.get_result(
        mol=molecule,
        bond_pair_ids=((0, 3), ),
        subunits=subunits,
    )

    final_bond_length = np.linalg.norm(
        optimizer._get_bond_vector(
            position_matrix=results.get_position_matrix(),
            bond_pair=(0, 3),
        ), )
    # Give it some wiggle room.
    assert 1.5 < final_bond_length
    assert final_bond_length < 2.5

    # Test all other bond lengths are equivalent.
    for bond in molecule.get_bonds():
        if (bond.get_atom1_id(), bond.get_atom2_id()) != (0, 3):
            test = get_atom_distance(
                position_matrix=results.get_position_matrix(),
                atom1_id=bond.get_atom1_id(),
                atom2_id=bond.get_atom2_id(),
            )
            bond_length = get_atom_distance(
                position_matrix=original_pos_mat,
                atom1_id=bond.get_atom1_id(),
                atom2_id=bond.get_atom2_id(),
            )
            assert np.isclose(test, bond_length, atol=1E-6)
Exemplo n.º 3
0
def test_get_atom_distance():
    position_matrix = np.array([
        [0, 0, 0],
        [0, 1, 0],
        [2, 0, 0],
    ])
    assert get_atom_distance(position_matrix, 0, 1) == 1
    assert get_atom_distance(position_matrix, 0, 2) == 2