Пример #1
0
def test_cart_frac_conversion():
    import numpy as np
    from chemtorch.structure.lattice import standardize_lattice
    from chemtorch.structure.coordinates import frac2cart
    from chemtorch.structure.coordinates import cart2frac

    l0 = []
    l1 = np.random.rand(1, 1) * 5
    l2 = np.random.rand(2, 2) * 5
    l3 = np.random.rand(3, 3) * 5

    l0 = standardize_lattice(l0)
    l1 = standardize_lattice(l1)
    l2 = standardize_lattice(l2)
    l3 = standardize_lattice(l3)

    L = [l0, l1, l2, l3]

    # 3 dimensional coordinates
    R = np.random.rand(10, 3) * 5
    for l in L:
        R0 = R.copy()
        R1 = frac2cart(cart2frac(R0, l), l)
        R0 = R1.copy()
        R1 = frac2cart(cart2frac(R0, l), l)
        print(len(l), "dimension conversional")
        print("First row of the coordinate is", R1[0])
        print("maximum error is", np.max(R1 - R0))

    # 4 dimensional coordinates
    l4 = np.random.rand(4, 4) * 5
    l4 = standardize_lattice(l4)
    L.append(l4)
    R = np.random.rand(10, 4) * 5
    for l in L:
        R0 = R.copy()
        R1 = frac2cart(cart2frac(R0, l), l)
        R0 = R1.copy()
        R1 = frac2cart(cart2frac(R0, l), l)
        print(len(l), "dimension conversional")
        print("First row of the coordinate is", R1[0])
        print("maximum error is", np.max(R1 - R0))
Пример #2
0
mlp = [num_feat, 50, 50, 50, num_engy]
weights, biases = get_weights(mlp, xavier=True), get_biases(mlp)
optimizer = torch.optim.Adam(biases + weights, lr=1e-4)

featFile = "tests\\data\\feat" if platform == 'win32' else "tests/data/feat"
engyFile = "tests\\data\\engy" if platform == 'win32' else "tests/data/engy"
filename = "tests\data\MOVEMENT.train" if platform == 'win32' else "tests/data/MOVEMENT.train"
mmt = read_PWMat_movement(filename,
                          get_forces=True,
                          get_velocities=True,
                          get_Ei=True,
                          get_Epot=True)

for iteration, (n_atoms, lattice, atom_types, Rfrac, F, V, Ei,
                Epot) in enumerate(mmt):
    lattice = standardize_lattice(lattice)
    Rcart = frac2cart(Rfrac, lattice)
    idxNb, Rij, maxNb = get_nb(Rcart, lattice, dcut=6.2)
    dij, dijk, Rhat = get_distances(Rij)
    g, g_dldl, g_dpdl = get_d_features(dij, dijk, Rhat, M2, M3, Router=6.2)

    x = torch.from_numpy(g.astype(np.float32))
    y = torch.from_numpy(Ei[:, None].astype(np.float32))

    print(iteration)

    pd.DataFrame(g.astype(np.float32)).to_csv(featFile,
                                              header=False,
                                              index=False,
                                              mode="a")
    pd.DataFrame(Ei[:, None].astype(np.float32)).to_csv(engyFile,