def all_train_and_test_from_outside():
    os.system('cp ../data_prescreening/input.json  ./')
    file_json = 'input.json'
    xxx_input = sub_inp_json.load_json(file_json)
    n_traj_select_train = int(xxx_input['n_traj_select_train'])
    n_x_dim = int(xxx_input['n_x_dim'])
    n_y_dim = int(xxx_input['n_y_dim'])
    label_x_descriptor = int(xxx_input['label_x_descriptor'])
    n_train_geom = int(xxx_input['n_train'])

    #      Copy geometries and energies
    curr_dir = os.getcwd()
    # -----------------------------------------------------
    sub_copy_data.copy_and_check_from_outside(n_traj_select_train)
    os.chdir(curr_dir)

    #     Collect all data
    # -----------------------------------------------------
    sub_collect_x_y.collect_all_from_file()
    os.chdir(curr_dir)
    # ----------------------------------------------------------------
    filename = descriptor_file(label_x_descriptor)
    sub_select_train_test.get_train_test_from_outside(n_train_geom, filename,
                                                      n_x_dim, n_y_dim)
    os.chdir(curr_dir)
Exemple #2
0
def make():
    curr_path = os.getcwd()
    work_path = curr_path + "/all"
    inp = json.load_json('inp.json')
    i_dimension = int(inp['mds_dimension'].encode('utf-8'))
    job = inp['job_select']
    os.chdir(work_path)
    classical_mds(i_dimension,job)  
    os.chdir(curr_path)
Exemple #3
0
def make():
    curr_path = os.getcwd()
    work_path = curr_path + "/all"
    inp = json.load_json('inp.json')
    distance_cutoff = float(inp['rmsd_cutoff'].encode('utf-8'))
    n_dimension = int(inp['mds_dimension'].encode('utf-8'))
    os.chdir(work_path)
    analy_result(n_dimension, distance_cutoff)
    os.chdir(curr_path)
Exemple #4
0
def Exch(coord):
    inp = json.load_json('inp.json')
    exch = []
    exch = eval(inp['exch_matrix'].encode('utf-8'))
    list1 = inp['exch_list']
    natom = inp['n_atom']
    list2 = []
    change_save = []
    change_save = exch_atom(coord, exch, list1, natom)
    return change_save
Exemple #5
0
def make_first():
    inp = json.load_json('inp.json')
    n_geom = int(inp['n_geom'])
    n_atom = int(inp['n_atom'])
    npro = int(inp['n_pro'])
    curr_path = os.getcwd()
    dir_path = curr_path + '/all/'
    command = 'cp inp.json ' + dir_path
    os.system(command)
    rmsd_many(n_geom, n_atom, npro)
Exemple #6
0
def make_second(id, workdir):
    n_geom = id
    inp = json.load_json('inp.json')
    n_atom = int(inp['n_atom'])
    npro = int(inp['n_pro'])
    dir_path = workdir
    command = 'cp inp.json ' + dir_path
    os.system(command)
    os.chdir(dir_path)
    rmsd_many(n_geom, n_atom, npro)
    def __init__(self, coord1, coord2):

        inp = json.load_json('inp.json')
        self.charality = inp['charality']
        self.exchange = inp['exchange']
        self.exchnu = None
        self.atom = inp['n_atom']
        self.coord1 = coord1
        self.coord2 = coord2
        self.mina = None
        self.geom_mina = None
        self.rmsd_list = []
        self.num = 0
 def __init__(self):
     file_json = 'input.json'
     xxx_input = sub_inp_json.load_json(file_json)
     self.rescale = xxx_input['rescale']
     self.n_x_dim = int(xxx_input['n_x_dim'])
     self.n_y_dim = int(xxx_input['n_y_dim'])
     self.para_gamma = xxx_input['para_gamma']
     self.para_alpha = xxx_input['para_alpha']
     self.para_kernel = xxx_input['para_kernel']
     self.para_gamma = self.para_gamma[1:-1]
     self.para_gamma = self.para_gamma.split(',')
     self.para_alpha = self.para_alpha[1:-1]
     self.para_alpha = self.para_alpha.split(',')
     self.npro_train = int(xxx_input['npro_train'])
Exemple #9
0
def make_first():
    inp = json.load_json('inp.json')
    npro = int(inp['n_pro'])
    ntraj = int(inp['n_traj'])
    dis = np.arange(ntraj * ntraj).reshape(ntraj, ntraj)
    dis = dis.astype(float)
    print dis
    for i in range(ntraj):
        for j in range(ntraj):
            print i, j
            path1 = i + 1
            path2 = j + 1
            curr_path = os.getcwd()
            dis[i, j] = rmsd_many(path1, path2, npro)
    print dis
    np.savetxt('similarity.dat', dis)
Exemple #10
0
    def __init__(self, dir_fit_dat, dir_all_traj, dir_result):
        self.home_dir = os.getcwd()
        self.dir_fit_dat = dir_fit_dat
        self.dir_all_traj = dir_all_traj
        self.dir_result = dir_result

        com = 'cp ' + dir_fit_dat + '/input.json  ./'
        os.system(com)
        file_json = 'input.json'
        xxx_input = sub_inp_json.load_json(file_json)

        self.n_atom = int(xxx_input['n_atom'])
        self.n_traj = int(xxx_input['n_traj'])
        self.n_x_dim = int(xxx_input['n_x_dim'])
        self.n_y_dim = int(xxx_input['n_y_dim'])
        self.n_state = self.n_y_dim
        self.para_gamma = xxx_input['para_gamma'][1:-1].split(',')
        self.para_alpha = xxx_input['para_alpha'][1:-1].split(',')
        self.para_kernel = xxx_input['para_kernel']
        self.npro_train = int(xxx_input['npro_train'])

        self.fit_files = ['fitting_para.dat', 'x_train.dat', 'y_train.dat', 'x_range.dat']
        gamma = self.para_gamma[0]
        alpha = self.para_alpha[0]
        i_state = 0
        dir_gamma = '/fit_result_kkr_gamma_' + str(gamma) + \
                    '_alpha_' + str(alpha) + \
                    '_S' + str(i_state)
        tmp_dir = self.dir_fit_dat + dir_gamma
        list_tmp = os.listdir(tmp_dir)
        for ffile in list_tmp:
            m = re.match('kkr.pkl', ffile)
            if m:
                self.fit_files.append(ffile)

        self.filename_pe_dyn_gather = 'pe_time_aferselect.out'
        self.filename_geom_dyn_sample = 'geom.xyz'
        self.filename_grad_dyn_sample = 'grad_dyn.xyz'
        self.filename_grad_kkr_sample = 'gradient_1d.xyz'
        self.filename_grad_kkr_gather = 'grad_kkr.xyz'
        self.filename_grad_cmp_sample = '/grad_cmp.dat'
        self.filename_grad_cmp_gather = '/grad_cmp.dat'
Exemple #11
0
 def __init__(self):
     self.inp = json.load_json('inp.json')
     self.rmsd_matrix = []
     self.savelist = []
def kkr_single_geom_all():
    kkrname = "kkr.json"
    xxx_input = sub_inp_json.load_json(kkrname)
    n_x_dim = int(xxx_input['n_x_dim'])
    n_y_dim = int(xxx_input['n_y_dim'])
    label_x_descriptor = int(xxx_input['label_x_descriptor'])
    para_kernel = xxx_input['para_kernel']
    rescale = xxx_input['rescale']
    label_grad = xxx_input['label_grad']
    para_alpha = float(xxx_input['para_alpha'])
    para_gamma = float(xxx_input['para_gamma'])
    energy_zero = float(xxx_input['energy_zero'])

    curr_dir = os.getcwd()

    kkr_path = './kkr'

    x_train = np.loadtxt('./kkr/x_train.dat')

    for i_y_dim in range(n_y_dim):
        work_path = kkr_path + '/' + str(i_y_dim + 1)
        os.chdir(work_path)
        os.system('rm -rf coulomb_input.dat distance_matrix.dat gradient_1d.xyz x_inversed_input.dat')
        os.system(
            'rm -rf coulomb_matrix.dat energy_gradient_col.dat geom.xyz gradient.xyz standard.xyz x_input.dat x_pre.dat')
        os.system('cp ../../geom.xyz .')
        fit_path = './'
        work_path = './'
        kkr_single_all = kkr_single_all_step(n_x_dim, n_y_dim, x_train, para_kernel, para_gamma, para_alpha, fit_path,
                                             work_path,
                                             rescale, label_grad, label_x_descriptor)
        kkr_single_all.kkr_all_step()
        os.chdir(curr_dir)

    file_kkr_result = open('qm_results.dat', 'w')
    file_geom = open('geom.xyz', 'r')
    n_atom = int(file_geom.readline())
    file_geom.readline()
    file_kkr_result.write('  ' + str(n_atom) + '\n')
    file_kkr_result.write(' The coordinates\n')
    for i_atom in range(n_atom):
        line_text = file_geom.readline().split()
        line_text[1] = float(line_text[1]) / 0.529
        line_text[2] = float(line_text[2]) / 0.529
        line_text[3] = float(line_text[3]) / 0.529
        file_kkr_result.write(
            str(line_text[0]) + ' ' + str(line_text[1]) + ' ' + str(line_text[2]) + ' ' + str(line_text[3]) + '\n')
    file_geom.close()

    file_kkr_result.write(' Energy of electronic states\n')
    for i_y_dim in range(n_y_dim):
        kkr_file = kkr_path + '/' + str(i_y_dim + 1) + '/' + 'gradient.xyz'
        file_kkr_pre = open(kkr_file, 'r')
        file_kkr_pre.readline()
        file_kkr_pre.readline()
        for i_atom in range(n_atom):
            file_kkr_pre.readline()
        line_text = file_kkr_pre.readline().split()
        kkr_energy = energy_zero + float(line_text[3])
        file_kkr_result.write(str(kkr_energy) + '\n')
        file_kkr_pre.close()

    file_kkr_result.write('Gradient of electronic states\n')
    for i_y_dim in range(n_y_dim):
        file_kkr_result.write(' State: ' + str(i_y_dim + 1) + '\n')
        kkr_file = kkr_path + '/' + str(i_y_dim + 1) + '/' + 'gradient.xyz'
        file_kkr_pre = open(kkr_file, 'r')
        file_kkr_pre.readline()
        file_kkr_pre.readline()
        for i_atom in range(n_atom):
            file_kkr_pre.readline()

        file_kkr_pre.readline()
        file_kkr_pre.readline()
        file_kkr_pre.readline()

        for i_atom in range(n_atom):
            file_kkr_result.write(file_kkr_pre.readline())
        file_kkr_pre.close()

    file_kkr_result.close()
Exemple #13
0
#! /usr/bin/env python
import rmsd_analys
import mds_cla
import mds_analys
import sub_inp_json as json
import os
import shutil

inp = json.load_json('inp.json')
inp['job_select'] = raw_input(
    "which job do u choose,classical or isomap(classical/isomap):")
inp['rmsd_cutoff'] = raw_input("Input the rmsd_cutoff value:")
if inp['job_select'] == 'isomap':
    inp['mds_cutoff'] = raw_input("Input the mds_cutoff value:")
inp['mds_dimension'] = raw_input("Choose mds dimension:")
json.dump_json('inp.json', inp)

if inp['job_select'] == 'isomap':
    file_name = inp['job_select'] + '_rmsdcut_' + inp[
        'rmsd_cutoff'] + '_mdscut_' + inp['mds_cutoff']
if inp['job_select'] == 'classical':
    file_name = inp['job_select'] + '_rmsdcut_' + inp['rmsd_cutoff']
curr_dir = os.getcwd()
workdir = curr_dir + '/' + file_name
if os.path.exists(workdir):
    shutil.rmtree(workdir)
os.mkdir(workdir)
command1 = 'cp -r all ' + workdir
command2 = 'cp inp.json ' + workdir
os.system(command1)
os.system(command2)
Exemple #14
0
def additional_test():
    os.system('cp ../train_and_test/input.json  ./')

    file_json = 'input.json'
    xxx_input = sub_inp_json.load_json(file_json)
    n_traj_test = int(xxx_input['n_predict_traj'])
    n_x_dim = int(xxx_input['n_x_dim'])
    n_y_dim = int(xxx_input['n_y_dim'])
    label_x_descriptor = int(xxx_input['label_x_descriptor'])
    para_gamma = xxx_input['para_gamma']
    para_alpha = xxx_input['para_alpha']
    para_gamma = para_gamma[1:-1]
    para_gamma = para_gamma.split(',')
    para_alpha = para_alpha[1:-1]
    para_alpha = para_alpha.split(',')
    para_kernel = xxx_input['para_kernel']
    rescale = xxx_input['rescale']
    npro_train = int(xxx_input['npro_train'])

    print("Copy add geometries for testing!")
    curr_dir = os.getcwd()
    sub_copy_additional_test_data.copy_geom_energy(n_traj_test)
    os.chdir(curr_dir)

    print("collect all geometries for testing!")
    #     Collect all data
    # -----------------------------------------------------
    sub_collect_x_y.collect_all_traj(n_traj_test)
    os.chdir(curr_dir)
    # ----------------------------------------------------------------
    filename = descriptor_file(label_x_descriptor)
    construct_data_input(n_traj_test, filename, n_x_dim, n_y_dim)
    os.chdir(curr_dir)

    #   Additional Test
    if npro_train > 1:
        pool = multiprocessing.Pool(processes=npro_train)
        print("Start work on test")
        for para_gamma1 in para_gamma:
            for para_alpha1 in para_alpha:
                for i_state in range(n_y_dim):
                    pool.apply_async(test_single, (
                        para_gamma1,
                        para_alpha1,
                        i_state,
                        n_traj_test,
                        n_x_dim,
                        para_kernel,
                        rescale,
                    ))

        pool.close()
        pool.join()
    elif npro_train == 1:
        for para_gamma1 in para_gamma:
            for para_alpha1 in para_alpha:
                for i_state in range(n_y_dim):
                    test_single(para_gamma1, para_alpha1, i_state, n_traj_test,
                                n_x_dim, para_kernel, rescale)

    plot_dir = 'plot_result'
    if os.path.exists(plot_dir):
        command1 = 'rm -r ' + str(plot_dir)
        os.system(command1)
    os.system('mkdir plot_result')
    for para_gamma1 in para_gamma:
        for para_alpha1 in para_alpha:
            plot_many_pes_time(n_traj_test, n_y_dim, para_gamma1, para_alpha1)
            os.chdir(curr_dir)