Esempio n. 1
0
def test_specified_c_table_assert_first_three_nonlinear():
    path = os.path.join(STRUCTURE_PATH, 'MIL53_beta.xyz')
    molecule = cc.Cartesian.read_xyz(path, start_index=1)
    fragment = molecule.get_fragment([(12, 2), (55, 2), (99, 2)])
    connection = fragment.get_construction_table()
    connection.loc[2] = [99, 12, 18]
    connection.loc[8] = [2, 99, 12]
    connection = connection.loc[[2, 8]]
    c_table = molecule.get_construction_table(fragment_list=[(fragment,
                                                              connection)],
                                              perform_checks=False)
    with pytest.raises(UndefinedCoordinateSystem):
        c_table = molecule.correct_dihedral(c_table)

    new = c_table.iloc[:4].copy()

    new.loc[99] = c_table.loc[17]
    new.loc[17] = c_table.loc[99]
    new = new.loc[[17, 12, 55, 99]]
    new.loc[12, 'b'] = 17
    new.loc[55, 'b'] = 17
    new.loc[99, 'a'] = 17

    c_table = molecule.get_construction_table(
        fragment_list=[(molecule.get_without(fragment)[0],
                        new), (fragment, connection)])
    c_table = molecule.correct_dihedral(c_table)
    zmolecule = molecule.get_zmat(c_table)
    assert allclose(molecule,
                    zmolecule.get_cartesian(),
                    align=False,
                    atol=1e-6)
Esempio n. 2
0
def test_concat_with_zmats():
    path = os.path.join(STRUCTURES, 'MIL53_small.xyz')
    m = cc.Cartesian.read_xyz(path, start_index=1)
    zm = m.get_zmat()
    zm1 = zm.change_numbering(new_index=range(1, len(zm) + 1))
    zm2 = zm.change_numbering(new_index=zm1.index + len(zm1))

    new = cc.xyz_functions.concat(
        [zm1.get_cartesian(),
         zm2.get_cartesian() + [0, 0, 10]])

    c_table = zm2.loc[:, ['b', 'a', 'd']]
    c_table.loc[57, ['b', 'a', 'd']] = [4, 1, 2]
    c_table.loc[58, ['a', 'd']] = [1, 2]
    c_table.loc[59, 'd'] = 1

    large_c_table = new.get_construction_table(
        fragment_list=[(zm2.get_cartesian(), c_table)])
    znew = new.get_zmat(large_c_table)

    cc.xyz_functions.allclose(new, znew.get_cartesian())

    znew.safe_loc[57, 'bond'] = 20. - 0.89
    assert allclose(
        zm1.get_cartesian().append(zm2.get_cartesian() + [0, 0, 20]),
        znew.get_cartesian())
Esempio n. 3
0
def test_concat():
    path = os.path.join(STRUCTURES, 'MIL53_small.xyz')
    molecule = cc.Cartesian.read_xyz(path)
    cartesians = [molecule + i * 10 for i in range(5)]

    with pytest.raises(ValueError):
        cc.xyz_functions.concat(cartesians)

    joined = cc.xyz_functions.concat(cartesians, ignore_index=True)
    for i, molecule in enumerate(cartesians):
        molecule2 = joined.iloc[(i * len(molecule)):(i + 1) * len(molecule)]
        molecule2.index = molecule.index
        assert allclose(molecule, molecule2)

    key_joined = cc.xyz_functions.concat(cartesians, keys=['a', 'b'])
    assert allclose(key_joined.loc['a'], (key_joined.loc['b'] - 10))
Esempio n. 4
0
def test_write_and_read():
    # Created because of https://github.com/mcocdawc/chemcoord/issues/58
    water_1 = cc.Cartesian.read_xyz(
        join(STRUCTURE_PATH, 'water.xyz'), start_index=1)
    z_water_str = water_1.get_zmat().to_zmat(upper_triangle=True)
    water_2 = cc.Zmat.read_zmat(StringIO(z_water_str)).get_cartesian()
    assert allclose(water_1, water_2, atol=1e-6)

    z_water_str = water_1.get_zmat().to_zmat(upper_triangle=False)
    cc.Zmat.read_zmat(StringIO(z_water_str)).get_cartesian()
Esempio n. 5
0
def back_and_forth(filepath):
    molecule1 = cc.Cartesian.read_xyz(filepath)
    zmolecule = molecule1.get_zmat()
    molecule2 = zmolecule.get_cartesian()
    assert allclose(molecule1, molecule2, align=False, atol=1e-7)
Esempio n. 6
0
def test_overloaded_operators():
    assert allclose(molecule + 1, molecule + [1, 1, 1])
    assert allclose(1 + molecule, molecule + [1, 1, 1])
    assert allclose(molecule + molecule, 2 * molecule)
    index = molecule.index
    assert allclose(molecule + molecule.loc[reversed(index)], 2 * molecule)
    assert allclose(molecule + molecule.loc[:, ['x', 'y', 'z']].values,
                    2 * molecule)
    assert allclose(1 * molecule, molecule)
    assert allclose(molecule * 1, molecule)
    assert allclose(1 * molecule, +molecule)
    assert allclose(-1 * molecule, -molecule)
    assert allclose(-molecule, 0 - molecule)
    assert allclose(molecule, molecule - 0)
    molecule2 = molecule[~(np.isclose(molecule['x'], 0)
                           | np.isclose(molecule['y'], 0)
                           | np.isclose(molecule['z'], 0))]
    assert np.allclose(np.full(molecule2.loc[:, ['x', 'y', 'z']].shape, 1),
                       (molecule2 / molecule2).loc[:, ['x', 'y', 'z']])
    assert np.allclose(np.full(molecule2.loc[:, ['x', 'y', 'z']].shape, 0),
                       (molecule2 - molecule2).loc[:, ['x', 'y', 'z']])