<jupyter_start><jupyter_text>3 Here<jupyter_code>test = []
test + [1,2]

# test and extract the lowest one

ditance_bw_all = []
total_E_all = []

datasets = []

extra_e_v = np.array([8e9,0,0])
#-------IMPORTANT-------BELOW-------O_O_mini_dist-------
O_O_mini_dist = 0.28 #unit in nm. 0.25
#Na_O_mini_dist = 0.18 #unit in nm.0.19
#Na_O_max_dist = 0.33 #unit in nm.0.19

H_H_mini_dist = 1.3e-10 #unit in m. 1.3e-10

lowest_db = []
lowest_total_dist = []
lowest_totalE = []

lowest_theta = []
lowest_phi = []
for kk in range(50):
    ditance_bw_all = []
    total_E_all = []
    datasets = []
    #-------IMPORTANT-------BELOW-------range(1000)-------
    for i in range(25):
        while True: # test the genrated coord. set, if dist bw O-O < O_O_mini_dist, regenate the coord. sets
            #inside the loop, generate another set
            xa=np.random.rand(6)
            ya=np.random.rand(6)
            za=np.random.rand(6)
            thetar=np.random.rand(6)*np.pi*2 
            phir=np.random.rand(6)*np.pi*2 
            moltypes =[1,1,1,1,1,1]

            xyza = np.stack((np.array(xa), np.array(ya),np.array(za)), axis=-1)

            
            #calculate the total E for this generated sys.
            rall,qall = allatomposns(moltypes,xa,ya,za,phir,thetar)
            rall = np.array(rall)*1e-9
            potl_E_sum = potl_energy_sum_electrode(rall,qall,extra_e_v)
            #print(potl_E_sum)
            rall_HA = rall[1::3]
            rall_HB = rall[2::3]
            rall_Hs = np.concatenate((rall_HA,rall_HB),axis=0)

            #if constrain01(xyza_5,O_O_mini_dist) and constrain02(xyza_5,Na_O_mini_dist,Na_O_max_dist) and constrain03(rall_Hs,H_H_mini_dist):
            #if constrain01(xyza_5,O_O_mini_dist) and constrain02(xyza_5,Na_O_mini_dist) \
             #                                    and potl_E_sum < -8.2e-19 \
             #                                    and constrain03(rall_Hs,H_H_mini_dist):
            if potl_E_sum < -6.7e-18 and constrain01(xyza,O_O_mini_dist):

                break
            else:
                continue

        # then, use this generated coord, save the data


        datasets.append([moltypes,xa,ya,za,phir,thetar])# all the succeed coord. set is saved here
        #calculate the total distance
        ditance_bw_all.append(total_dist(rall))
        #calculate the total E_energy
        total_E_all.append(potl_E_sum)# all the total E_energy of the succeed coord. set are saved here
    #------the coord. set finishing generating------

    #for all the successfully generated coord. sets, find the lowest one
    total_E_all = np.array(total_E_all)
    datasets = np.array(datasets)
    lowest_index = np.argmin(total_E_all)
    

    
    #For this lowest one
    lowest_db.append([datasets[lowest_index][0],datasets[lowest_index][1],datasets[lowest_index][2],\
                         datasets[lowest_index][3],datasets[lowest_index][4],datasets[lowest_index][5]])
    # calculate the lowest energy 
    rall,qall = allatomposns(datasets[lowest_index][0],datasets[lowest_index][1],datasets[lowest_index][2],\
                             datasets[lowest_index][3],datasets[lowest_index][4],datasets[lowest_index][5])
    rall = np.array(rall)*1e-9
    potl_E_sum = potl_energy_sum_electrode(rall,qall,extra_e_v)
    
    print('The lowest E_energy - potl_E_sum:',potl_E_sum, 'J')
    lowest_totalE.append(potl_E_sum)
    lowest_total_dist.append(total_dist(rall))

    
    lowest_theta = np.concatenate((datasets[lowest_index][5], lowest_theta))
    lowest_phi = np.concatenate((datasets[lowest_index][4], lowest_phi))

#-------plot------Total E against total distance-------
#plot all the possible coord.
plt.figure(figsize=(8,5.5)) 
plt.title('total E against total distance between all pairs',fontsize=14)
plt.plot(lowest_total_dist, lowest_totalE, marker='.',linestyle = '')

plt.xlabel('total distance(nm)')
plt.ylabel('total E (J)')
plt.show();
plt.figure(figsize=(8,5.5)) 
plt.title('total E against total distance between all pairs',fontsize=14)
plt.plot(lowest_total_dist, lowest_totalE, marker='.',linestyle = '')

plt.xlabel('total distance(nm)')
plt.ylabel('total E (J)')
plt.show();
plt.title('Histogram of Theta angle')
plt.hist(lowest_theta, bins=30)
plt.xlabel('Theta angle / radian')
plt.ylabel('Frequency')
plt.show()


plt.title('Histogram of Phi angle')
plt.hist(lowest_phi, bins=30)
plt.xlabel('Phi angle / radian')
plt.ylabel('Frequency')
plt.show()
plt.figure(figsize=(8,5.5)) 
plt.title('total E against total distance between all pairs',fontsize=14)
plt.plot(lowest_total_dist, lowest_totalE, marker='.',linestyle = '',color='r')

plt.xlabel('total distance(nm)')
plt.ylabel('total E (J)')
plt.show();
# plot all the graphy for the sys with E lower than -8E-18 j
for lowest_index in range(len(lowest_db[:])):
    this_rall = []
    this_qall = []
    
    rall,qall = allatomposns(lowest_db[lowest_index][0],lowest_db[lowest_index][1],lowest_db[lowest_index][2],\
                         lowest_db[lowest_index][3],lowest_db[lowest_index][4],lowest_db[lowest_index][5])
    rall = np.array(rall)*1e-9
    potl_E_sum = potl_energy_sum_electrode(rall,qall,extra_e_v)
    print('This E_energy - potl_E_sum:',potl_E_sum, 'J')

    
    
    this_e = "{:.3g}".format(potl_energy_sum_electrode(rall,qall,extra_e_v))
    print('potl_E_sum:',this_e, 'J')
    
    
    xall=[]
    yall=[]
    zall=[]
    for i in range(int(len(rall))):
        xall.append(float(rall[i][0])*1e9)
        yall.append(float(rall[i][1])*1e9)
        zall.append(float(rall[i][2])*1e9)
    #print('xall:',xall)
    this_e = "{:.3g}".format(potl_energy_sum_electrode(rall,qall,extra_e_v))
    print('potl_E_sum:',this_e, 'J')

    #-------plot------3D-coord of the lowest E_energy-------
    #plot the lowest E atoms posi.(interactive)
    fig = make_subplots()
    O_atoms = go.Scatter3d(x=xall[::3], y=yall[::3], z=zall[::3],mode='markers',marker = {'color' : 'red'},name='Oxygen Atom')
    H_atoms01 = go.Scatter3d(x=xall[1::3], y=yall[1::3], z=zall[1::3],mode='markers',marker = {'color' : 'blue'},name='Hydrogen Atom')
    H_atoms02 = go.Scatter3d(x=xall[2::3], y=yall[2::3], z=zall[2::3],mode='markers',marker = {'color' : 'blue'},name='Hydrogen Atom')

    fig.add_trace(O_atoms)
    fig.add_trace(H_atoms01)
    fig.add_trace(H_atoms02)

    fig.update_layout(title_text=f'molecule positions (Total energy = {this_e} J)',title_x=0.5,width=800, height=600,scene_aspectmode='cube',
                    scene = dict(
                    xaxis_title='x (nm)',
                    yaxis_title='y (nm)',
                    zaxis_title='z (nm)',
                                 )
                     )

    fig.show()

for lowest_index in range(len(lowest_db[:])):
    this_rall = []
    this_qall = []
    
    rall,qall = allatomposns(lowest_db[lowest_index][0],lowest_db[lowest_index][1],lowest_db[lowest_index][2],\
                         lowest_db[lowest_index][3],lowest_db[lowest_index][4],lowest_db[lowest_index][5])
    rall = np.array(rall)*1e-9
    potl_E_sum = potl_energy_sum_electrode(rall,qall,extra_e_v)



    # plot all the graphy for the sys with E lower than -8E-18 j
    print('This E_energy - potl_E_sum:',potl_E_sum, 'J')

    #plot the interactive graphy
    
    
    #split OXYGEN atoms in red, HYDROGEN atoms in blue
    this_e = "{:.3g}".format(potl_energy_sum_electrode(rall,qall,extra_e_v))
    print('potl_E_sum:',this_e, 'J')


    title_here = 'potl_E_sum: '+this_e+ ' J'
    #-------plot------3D-coord of the lowest E_energy-------
    #plot the lowest E atoms posi.(interactive)
    @interact
    def make_plot_2(elevpara=(-27,90,3),azimpara=(-117,0,3)):
        f1,ax1 = mol_plot(moltypes,lowest_db[lowest_index][1],lowest_db[lowest_index][2],\
                         lowest_db[lowest_index][3],lowest_db[lowest_index][4],lowest_db[lowest_index][5])
        ax1.set_xlabel('x (nm)')
        ax1.set_ylabel('y (nm)')
        ax1.set_zlabel('z (nm)')
        ax1.set_title(title_here)
        ax1.set_aspect('auto')
        ax1.view_init(elev=elevpara, azim=azimpara) #adjust 'camera angle' with this command if desired - angles are in degrees
        f1.show();<jupyter_output>This E_energy - potl_E_sum: -7.118559818843949e-18 J
potl_E_sum: -7.12e-18 J
{'fraction_non_alphanumeric': 0.1557564798071127, 'fraction_numerical': 0.029053646775165764, 'mean_word_length': 3.068661108386464, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '142801', 'license': 'MIT', 'n_tokens_mistral': 3333, 'n_tokens_neox': 3162, 'n_words': 510, 'path': 'Part_2_Q3.ipynb', 'repo_name': 'notmuchgeek/MPC2_phy_proj', 'size': '8295'}