def do_analysis(dataset, molecules, s_raw, log_file):

    #--- calculate guesses ---
    msg.info("Calculating guesses ...",2)

    p_1e = np.array([
        hf.init_guess_by_1e(mol.get_pyscf_molecule()) for mol in molecules[1]
    ])
    p_sap = np.array([
        hf.init_guess_by_atom(mol.get_pyscf_molecule()) for mol in molecules[1]
    ])
    p_minao = np.array([
        hf.init_guess_by_minao(mol.get_pyscf_molecule()) for mol in molecules[1]
    ])
    p_gwh = np.array([
        hf.init_guess_by_wolfsberg_helmholtz(mol.get_pyscf_molecule()) for mol in molecules[1]
    ])
    #--- 

    with open(log_file, "a+") as f:
        f.write("\n\n+++++ H_Core +++++\n")
    msg.info("Results H_Core: ", 1)
    measure_and_display(
        p_1e.reshape(-1, DIM**2), dataset, molecules, False, log_file, s=s_raw
    )

    with open(log_file, "a+") as f:
        f.write("\n\n+++++ SAP +++++\n")
    msg.info("Results SAP: ", 1)
    measure_and_display(
        p_sap.reshape(-1, DIM**2), dataset, molecules, False, log_file, s=s_raw
    )

    with open(log_file, "a+") as f:
        f.write("\n\n+++++ MINAO +++++\n")
    msg.info("Results MINAO: ", 1)
    measure_and_display(
        p_minao.reshape(-1, DIM**2), dataset, molecules, False, log_file, s=s_raw
    )

    with open(log_file, "a+") as f:
        f.write("\n\n+++++ GWH +++++\n")
    msg.info("Results GWH: ", 1)
    measure_and_display(
        p_gwh.reshape(-1, DIM**2), dataset, molecules, False, log_file, s=s_raw
    )
Exemple #2
0
def do_analysis(network_path, dataset, molecules, s_raw, log_file):

    #--- fetch network ---
    msg.info("Fetching pretained network ", 2)
    graph = tf.Graph()
    structure, weights, biases = np.load(
        network_path, 
        encoding="latin1"
    )[:3]

    with graph.as_default():
        sess = tf.Session()
        network = EluFixedValue(structure, weights, biases)
        network.setup()
        sess.run(tf.global_variables_initializer())
    #---

    #--- calculate guesses ---
    msg.info("Calculating guesses ...",2)
    
    msg.info("Neural network ", 1)
    p_nn = network.run(sess, dataset.testing[0])

    msg.info("McWheenys", 1)
    p_batch = make_matrix_batch(p_nn, DIM, True)
    p_mcw1 = np.array(list(map(lambda x: multi_mc_wheeny(x[0], x[1], n_max=1), zip(p_batch, s_raw))))
    p_mcw5 = np.array(list(map(lambda x: multi_mc_wheeny(x[0], x[1], n_max=5), zip  (p_batch, s_raw))))

    msg.info("Classics", 1)
    p_1e = np.array([
        hf.init_guess_by_1e(mol.get_pyscf_molecule()) for mol in molecules[1]
    ])
    p_sap = np.array([
        hf.init_guess_by_atom(mol.get_pyscf_molecule()) for mol in molecules[1]
    ])
    p_minao = np.array([
        hf.init_guess_by_minao(mol.get_pyscf_molecule()) for mol in molecules[1]
    ])
    p_gwh = np.array([
        hf.init_guess_by_wolfsberg_helmholtz(mol.get_pyscf_molecule()) for mol in molecules[1]
    ])
    #--- 

    msg.info("Results NN: ", 1)
    with open(log_file, "a+") as f:
        f.write("\n+++++ Plain NN +++++\n")
    measure_and_display(
        p_nn, dataset, molecules, True, log_file, s=s_raw
    )
    
    with open(log_file, "a+") as f:
        f.write("\n\n+++++ McW 1 +++++\n")
    msg.info("Results McWheeny 1: ",1)
    measure_and_display(
        p_mcw1.reshape(-1, DIM**2), dataset, molecules, False, log_file, s=s_raw
    )
    
    with open(log_file, "a+") as f:
        f.write("\n\n+++++ McW 5 +++++\n")
    msg.info("Results McWheeny 5: ", 1)
    measure_and_display(
        p_mcw5.reshape(-1, DIM**2), dataset, molecules, False, log_file, s=s_raw
    )

    with open(log_file, "a+") as f:
        f.write("\n\n+++++ H_Core +++++\n")
    msg.info("Results H_Core: ", 1)
    measure_and_display(
        p_1e.reshape(-1, DIM**2), dataset, molecules, False, log_file, s=s_raw
    )

    with open(log_file, "a+") as f:
        f.write("\n\n+++++ SAP +++++\n")
    msg.info("Results SAP: ", 1)
    measure_and_display(
        p_sap.reshape(-1, DIM**2), dataset, molecules, False, log_file, s=s_raw
    )

    with open(log_file, "a+") as f:
        f.write("\n\n+++++ MINAO +++++\n")
    msg.info("Results MINAO: ", 1)
    measure_and_display(
        p_minao.reshape(-1, DIM**2), dataset, molecules, False, log_file, s=s_raw
    )

    with open(log_file, "a+") as f:
        f.write("\n\n+++++ GWH +++++\n")
    msg.info("Results GWH: ", 1)
    measure_and_display(
        p_gwh.reshape(-1, DIM**2), dataset, molecules, False, log_file, s=s_raw
    )
Exemple #3
0
def main(sample_index):

    msg.print_level = 2

    msg.info("Hi. Measurements for butadien", 2)

    #--- fetch dataset and constants ---
    msg.info("Fetching sample " + str(sample_index) + " from datase", 2)

    dim = DIM

    molecules = np.load(
        "butadien/data/molecules.npy"
    )
    S = np.load( "butadien/data/S.npy")
    P = np.load( "butadien/data/P.npy")
    dataset = make_butadien_dataset(molecules, S, P)[0]

    molecule = molecules[sample_index].get_pyscf_molecule()
    s = S[sample_index].reshape(dim, dim)
    s_normed = dataset.inverse_input_transform(s.reshape(1, -1)).reshape(1,-1)
    p = P[sample_index].reshape(dim, dim)
    #---

    #--- fetch network ---
    msg.info("Fetching pretained network ", 2)
    graph = tf.Graph()
    structure, weights, biases = np.load(
        "butadien/data/network.npy", 
        encoding="latin1"
    )
    
    with graph.as_default():
        sess = tf.Session()
        network = EluFixedValue(structure, weights, biases)
        network.setup()
        sess.run(tf.global_variables_initializer())
    #---

    #--- calculate guesses ---
    msg.info("Calculating guesses ...",2)
    
    msg.info("Neural network ", 1)
    p_nn = network.run(sess, s_normed).reshape(dim, dim)

    msg.info("McWheenys", 1)
    p_mcw1 = multi_mc_wheeny(p_nn, s, n_max=1)
    p_mcw5 = multi_mc_wheeny(p_nn, s, n_max=5)

    msg.info("Classics", 1)
    p_sap = hf.init_guess_by_atom(molecule)
    
    p_minao = hf.init_guess_by_minao(molecule)
    
    p_gwh = hf.init_guess_by_wolfsberg_helmholtz(molecule)
    #--- 

    #--- Measureing & print ---
    outfile = "butadien/results/cube_" + str(sample_index) + "_"
    
    msg.info("Results Converged ", 1)
    cubegen.density(molecule, outfile + "converged.cube", p.astype("float64"))

    msg.info("Results NN: ", 1)
    cubegen.density(molecule, outfile + "nn.cube", p_nn.astype("float64"))
    
    msg.info("Results McWheeny 1: ",1)
    cubegen.density(molecule, outfile + "mcw1.cube", p_mcw1.astype("float64"))
    
    msg.info("Results McWheeny 5: ", 1)
    cubegen.density(molecule, outfile + "mcw5.cube", p_mcw5.astype("float64"))

    msg.info("Results SAP: ", 1)
    cubegen.density(molecule, outfile + "sap.cube", p_sap)

    msg.info("Results MINAO: ", 1)
    cubegen.density(molecule, outfile + "minao.cube", p_minao)

    msg.info("Results GWH: ", 1)
    cubegen.density(molecule, outfile + "gwh.cube", p_gwh)
Exemple #4
0
def main(molecule_type):

    msg.print_level = 2

    msg.info("Hi. Measurements for " + molecule_type, 2)

    #--- fetch dataset and constants ---
    msg.info("Fetching dataset", 2)
    dataset_triu, molecules = fetch_dataset(molecule_type, True)
    dataset, _ = fetch_dataset(molecule_type, False)
    dim = DIM[molecule_type]
    #---

    #--- fetch network ---
    msg.info("Fetching pretained network ", 2)
    graph = tf.Graph()
    structure, weights, biases = np.load(
        "cc2ai/" + molecule_type + "/network_" + molecule_type + ".npy", 
        encoding="latin1"
    )
    #---

    with graph.as_default():
        sess = tf.Session()
        network = EluFixedValue(structure, weights, biases)
        network.setup()
        sess.run(tf.global_variables_initializer())
    #---

    #--- calculate guesses ---
    msg.info("Calculating guesses ...",2)
    s_raw = make_matrix_batch(dataset_triu.inverse_input_transform(dataset_triu.testing[0]), dim, True)
    
    msg.info("Neural network ", 1)
    p_nn = network.run(sess, dataset_triu.testing[0])

    msg.info("McWheenys", 1)
    p_batch = make_matrix_batch(p_nn, dim, True)
    p_mcw1 = np.array(list(map(lambda x: multi_mc_wheeny(x[0], x[1], n_max=1), zip(p_batch, s_raw))))
    p_mcw5 = np.array(list(map(lambda x: multi_mc_wheeny(x[0], x[1], n_max=5), zip  (p_batch, s_raw))))

    msg.info("Classics", 1)
    p_1e = np.array([
        hf.init_guess_by_1e(mol.get_pyscf_molecule()) for mol in molecules[1]
    ])
    p_sap = np.array([
        hf.init_guess_by_atom(mol.get_pyscf_molecule()) for mol in molecules[1]
    ])
    p_minao = np.array([
        hf.init_guess_by_minao(mol.get_pyscf_molecule()) for mol in molecules[1]
    ])
    p_gwh = np.array([
        hf.init_guess_by_wolfsberg_helmholtz(mol.get_pyscf_molecule()) for mol in molecules[1]
    ])
    #--- 

    #--- Measureing & print ---
    log_file = "cc2ai/" + molecule_type + "/pretrained_" + str(date.today()) + ".log"
    with open(log_file, "a+") as f:
        f.write("##### Analysis of " + str(datetime.now()) + " #####\n")
    msg.info("Results NN: ", 1)
    with open(log_file, "a+") as f:
        f.write("\n+++++ Plain NN +++++\n")
    measure_and_display(
        p_nn, dataset_triu, molecules, molecule_type, True, log_file
    )
    
    with open(log_file, "a+") as f:
        f.write("\n\n+++++ McW 1 +++++\n")
    msg.info("Results McWheeny 1: ",1)
    measure_and_display(
        p_mcw1.reshape(-1, dim**2), dataset, molecules, molecule_type, False, log_file
    )
    
    with open(log_file, "a+") as f:
        f.write("\n\n+++++ McW 5 +++++\n")
    msg.info("Results McWheeny 5: ", 1)
    measure_and_display(
        p_mcw5.reshape(-1, dim**2), dataset, molecules, molecule_type, False, log_file
    )

    with open(log_file, "a+") as f:
        f.write("\n\n+++++ H_Core +++++\n")
    msg.info("Results H_Core: ", 1)
    measure_and_display(
        p_1e.reshape(-1, dim**2), dataset, molecules, molecule_type, False, log_file
    )

    with open(log_file, "a+") as f:
        f.write("\n\n+++++ SAP +++++\n")
    msg.info("Results SAP: ", 1)
    measure_and_display(
        p_sap.reshape(-1, dim**2), dataset, molecules, molecule_type, False, log_file
    )

    with open(log_file, "a+") as f:
        f.write("\n\n+++++ MINAO +++++\n")
    msg.info("Results MINAO: ", 1)
    measure_and_display(
        p_minao.reshape(-1, dim**2), dataset, molecules, molecule_type, False, log_file
    )

    with open(log_file, "a+") as f:
        f.write("\n\n+++++ GWH +++++\n")
    msg.info("Results GWH: ", 1)
    measure_and_display(
        p_gwh.reshape(-1, dim**2), dataset, molecules, molecule_type, False, log_file
    )