def gaussion_workers(chem_model, val): while True: simulation_time = time.time() task = comm.recv(source=0, tag=MPI.ANY_TAG, status=status) tag = status.Get_tag() if tag == START: state = task[0] m = task[1] all_posible = chem_kn_simulation(chem_model, state, val, m) generate_smile = predict_smile(all_posible, val) new_compound = make_input_smile(generate_smile) score = [] kao = [] try: m = Chem.MolFromSmiles(str(new_compound[0])) except: m = None #if m!=None and len(task[i])<=81: if m != None: try: logp = Descriptors.MolLogP(m) except: logp = -1000 SA_score = -sascorer.calculateScore( MolFromSmiles(new_compound[0])) cycle_list = nx.cycle_basis( nx.Graph( rdmolops.GetAdjacencyMatrix( MolFromSmiles(new_compound[0])))) if len(cycle_list) == 0: cycle_length = 0 else: cycle_length = max([len(j) for j in cycle_list]) if cycle_length <= 6: cycle_length = 0 else: cycle_length = cycle_length - 6 cycle_score = -cycle_length #print cycle_score #print SA_score #print logp SA_score_norm = (SA_score - SA_mean) / SA_std logp_norm = (logp - logP_mean) / logP_std cycle_score_norm = (cycle_score - cycle_mean) / cycle_std score_one = SA_score_norm + logp_norm + cycle_score_norm score.append(score_one) else: score.append(-1000) score.append(new_compound[0]) score.append(rank) comm.send(score, dest=0, tag=DONE) simulation_fi_time = time.time() - simulation_time print "simulation_fi_time:", simulation_fi_time if tag == EXIT: MPI.Abort(MPI.COMM_WORLD) comm.send(None, dest=0, tag=EXIT)
def __init__(self, npxyz, xyzL, xyz_orig, ncxyz): #initialise MPI and CPL self.comm = MPI.COMM_WORLD self.CPL = CPL() self.CFD_COMM = self.CPL.init(CPL.CFD_REALM) self.nprocs_realm = self.CFD_COMM.Get_size() # Parameters of the cpu topology (cartesian grid) self.npxyz = np.array(npxyz, order='F', dtype=np.int32) self.NProcs = np.product(npxyz) self.xyzL = np.array(xyzL, order='F', dtype=np.float64) self.xyz_orig = np.array(xyz_orig, order='F', dtype=np.float64) self.ncxyz = np.array(ncxyz, order='F', dtype=np.int32) if (self.nprocs_realm != self.NProcs): print("Non-coherent number of processes in CFD ", self.nprocs_realm, " no equal to ", self.npxyz[0], " X ", self.npxyz[1], " X ", self.npxyz[2]) MPI.Abort(errorcode=1) #Setup coupled simulation self.cart_comm = self.CFD_COMM.Create_cart( [self.npxyz[0], self.npxyz[1], self.npxyz[2]]) self.CPL.setup_cfd(self.cart_comm, self.xyzL, self.xyz_orig, self.ncxyz) #Get limits of overlap region self.olap_limits = self.CPL.get_olap_limits() self.portion = self.CPL.my_proc_portion(self.olap_limits) [self.ncxl, self.ncyl, self.nczl] = self.CPL.get_no_cells(self.portion) self.dx = self.CPL.get("xl_cfd") / float(self.CPL.get("ncx")) self.dy = self.CPL.get("yl_cfd") / float(self.CPL.get("ncy")) self.dz = self.CPL.get("zl_cfd") / float(self.CPL.get("ncz")) self.ioverlap = (self.CPL.get("icmax_olap") - self.CPL.get("icmin_olap") + 1) self.joverlap = (self.CPL.get("jcmax_olap") - self.CPL.get("jcmin_olap") + 1) self.koverlap = (self.CPL.get("kcmax_olap") - self.CPL.get("kcmin_olap") + 1) self.xoverlap = self.ioverlap * self.dx self.yoverlap = self.joverlap * self.dy self.zoverlap = self.koverlap * self.dz
def gaussion_workers(chem_model, val, gau_parallel, charge_check, output_file_name, lock): while True: simulation_time = time.time() task = comm.recv(source=0, tag=MPI.ANY_TAG, status=status) tag = status.Get_tag() #print('rank_tag:',rank, tag) if tag == START: state = task[0] m = task[1] ind = task[2] new_compound = task[3] print "new compound:", new_compound score = [] kao = [] intensity = -1000000 deen = 1000000 gap = 1000000 mol_weight = 0 SA_score = 10 wavenum = -1000 logP = 0 dp = len(state) nmr_wasser = -1 intensity_list = [] wl_list = [] standard_valence_list = [ 0, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2 ] try: m = Chem.MolFromSmiles( Chem.MolToSmiles(Chem.MolFromSmiles(str(new_compound[0])), True)) mol_weight = Descriptors.MolWt(m) logP = Crippen.MolLogP(m) #SA_score = sascorer.calculateScore(m) #print 'prev add Hs' m_H = Chem.AddHs(m) #print Chem.MolToSmiles(m_H) standard_valence_list = [ 0, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2 ] ccheck = True if charge_check: for atom in m_H.GetAtoms(): #print standard_valence_list[atom.GetAtomicNum()], atom.GetExplicitValence() if standard_valence_list[atom.GetAtomicNum( )] != atom.GetExplicitValence(): ccheck = False break if not ccheck: m = None except: m = None if m != None: H_count = 0 C_count = 0 for atom in m.GetAtoms(): H_count = H_count + atom.GetTotalNumHs( includeNeighbors=False) if atom.GetSymbol() == 'C': C_count = C_count + 1 if H_count > target_outdic['nmr'][0].count( 'H') or C_count > target_outdic['nmr'][0].count('C'): nmr_wasser = -1 print(str(new_compound[0]), 'rejected', H_count, C_count) else: print(str(new_compound[0]), 'accepeted', H_count, C_count) try: stable = transfersdf(str(new_compound[0]), ind) except: stable = -1 print('warning: unstable') if stable == 1.0: cd_path = os.getcwd() try: SDFinput = 'CheckMolopt' + str(ind) + '.sdf' calc_sdf = GaussianDFTRun('B3LYP', '3-21G*', gau_parallel, 'nmr', SDFinput, 0) outdic = calc_sdf.run_gaussian() nmr_wasser = get_wasserstein_dist( outdic, target_outdic) print ind, '|', nmr_wasser, '|', new_compound[ 0], '|', outdic['nmr'] if os.path.isfile('CheckMol' + str(ind) + '.sdf'): shutil.move('CheckMol' + str(ind) + '.', 'dft_result') if os.path.isfile('CheckMolopt' + str(ind) + '.sdf'): shutil.move('CheckMolopt' + str(ind) + '.sdf', 'dft_result') except: os.chdir(cd_path) if os.path.isfile('CheckMolopt' + str(ind) + '.sdf'): os.remove('CheckMolopt' + str(ind) + '.sdf') if os.path.isfile('CheckMol' + str(ind) + '.sdf'): os.remove('CheckMol' + str(ind) + '.sdf') else: wavelength = None if os.path.isfile('CheckMolopt' + str(ind) + '.sdf'): os.remove('CheckMolopt' + str(ind) + '.sdf') if os.path.isfile('CheckMol' + str(ind) + '.sdf'): os.remove('CheckMol' + str(ind) + '.sdf') score.append(wavenum) score.append(new_compound[0]) score.append(rank) score.append(intensity) score.append(deen) score.append(gap) score.append(wl_list) score.append(intensity_list) score.append(ind) score.append(mol_weight) score.append(logP) score.append(SA_score) score.append(dp) score.append(nmr_wasser) comm.send(score, dest=0, tag=DONE) simulation_fi_time = time.time() - simulation_time ###print("simulation_fi_time:",simulation_fi_time) if tag == EXIT: MPI.Abort(MPI.COMM_WORLD) comm.send([-1000, '', 0, 0, 0, 0, [], [], ind, 0, 0, 0, 0], dest=0, tag=EXIT)
NPx = 3 NPy = 3 NPz = 3 NProcs = NPx * NPy * NPz # Parameters of the mesh topology (cartesian grid) ncxyz = np.array([18, 18, 18], order='F', dtype=np.int32) xyzL = np.array([10.0, 10.0, 10.0], order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) # Create communicators and check that number of processors is consistent realm_comm = CPL.create_comm(CPL.CFD_REALM) nprocs_realm = realm_comm.Get_size() if (nprocs_realm != NProcs): print "ERROR: Non-coherent number of processors." MPI.Abort(errorcode=1) cart_comm = realm_comm.Create_cart([NPx, NPy, NPz]) CPL.cfd_init2(nsteps, dt, cart_comm, xyzL, xyz_orig, ncxyz, 1.0) ols = CPL.get_olap_limits() my_coords = cart_comm.Get_coords(cart_comm.Get_rank()) my_coords = np.array(my_coords, order='F', dtype=np.int32) """ #if (True): # print str(cart_comm.Get_rank())+" "+ "mycoords: " + str(my_coords)+ "extents:" + str(extents)+ " "+str(nsteps)+ str(dt)+ str(cart_comm)+ \ # str(icoords)+ str(xyzL)+ str(ncxyz)+\ # str(1.0)+ str(ijkcmax)+ str(ijkcmin)+ str(iTmin)+ str(iTmax)\ # +str(jTmin)+ str(jTmax)+ str(kTmin)+ str(kTmax)
def gaussion_workers(chem_model, val): while True: simulation_time = time.time() task = comm.recv(source=0, tag=MPI.ANY_TAG, status=status) tag = status.Get_tag() if tag == START: state = task[0] m = task[1] ind = task[2] all_posible = chem_kn_simulation(chem_model, state, val, m) generate_smile = predict_smile(all_posible, val) new_compound = make_input_smile(generate_smile) score = [] kao = [] try: m = Chem.MolFromSmiles(str(new_compound[0])) except: m = None #if m!=None and len(task[i])<=81: if m != None: stable = tansfersdf(str(new_compound[0]), ind) if stable == 1.0: try: SDFinput = 'CheckMolopt' + str(ind) + '.sdf' calc_sdf = GaussianDFTRun('B3LYP', '6-31G', 1, 'uv homolumo', SDFinput, 0) outdic = calc_sdf.run_gaussian() wavelength = outdic['uv'][0] #gap=outdic['gap'][0] #lumo=outdic['gap'][1] except: wavelength = None else: wavelength = None if wavelength != None and wavelength != []: wavenum = wavelength[0] gap = outdic['gap'][0] lumo = outdic['gap'][1] else: wavenum = -1000 gap = -1000 lumo = -1000 else: wavenum = -1000 gap = -1000 lumo = -1000 #score.append(wavenum) score.append(gap) score.append(lumo) score.append(new_compound[0]) score.append(rank) comm.send(score, dest=0, tag=DONE) simulation_fi_time = time.time() - simulation_time print "simulation_fi_time:", simulation_fi_time if tag == EXIT: MPI.Abort(MPI.COMM_WORLD) comm.send(None, dest=0, tag=EXIT)
def gaussion_workers(chem_model, val, gau_parallel, charge_check): while True: simulation_time = time.time() task = comm.recv(source=0, tag=MPI.ANY_TAG, status=status) tag = status.Get_tag() if tag == START: state = task[0] m = task[1] ind = task[2] all_posible = chem_kn_simulation(chem_model, state, val, m) generate_smile = predict_smile(all_posible, val) new_compound = make_input_smile(generate_smile) score = [] kao = [] intensity = -1000000 deen = 1000000 gap = 1000000 mol_weight = 0 SA_score = 10 logP = 0 dp = len(state) intensity_list = [] wl_list = [] standard_valence_list = [ 0, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2 ] s1_wavenum = -1000 s1_strength = 0 s1_wavelength = None s1_wl_list = [] s1_str_list = [] try: m = Chem.MolFromSmiles(str(new_compound[0])) mol_weight = Descriptors.MolWt(m) logP = Crippen.MolLogP(m) SA_score = sascorer.calculateScore(m) #print 'prev add Hs' m_H = Chem.AddHs(m) #print Chem.MolToSmiles(m_H) standard_valence_list = [ 0, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2 ] ccheck = True if charge_check: for atom in m_H.GetAtoms(): #print standard_valence_list[atom.GetAtomicNum()], atom.GetExplicitValence() if standard_valence_list[atom.GetAtomicNum( )] != atom.GetExplicitValence(): ccheck = False break if not ccheck: #print 'charge checked: not' m = None #print 'charge checked' #if charge_check(m_H, standard_valence_list): # print('charge_check: OK') #else: # m = None except: m = None #if m!=None and len(task[i])<=81: if m != None: try: stable = tansfersdf(str(new_compound[0]), ind) except: stable = -1 if stable == 1.0: cd_path = os.getcwd() try: SDFinput = 'CheckMolopt' + str(ind) + '.sdf' #wavelength=GauTDDFT_ForDFT('B3LYP', '3-21G*', 1, 'CheckMolopt'+str(ind)+'.sdf') #STO3G calc_sdf = GaussianDFTRun( 'B3LYP', '3-21G*', gau_parallel, 'OPT fluor energy deen uv homolumo', SDFinput, 0) outdic = calc_sdf.run_gaussian() wavelength = outdic['uv'][0] s1_wavelength = outdic[ 'S1 Wavelength and Oscillator strengths'][0] print('ind', ind, 'wavelength', wavelength) if os.path.isfile('CheckMol' + str(ind) + '.sdf'): shutil.move('CheckMol' + str(ind) + '.sdf', 'dft_result') if os.path.isfile('CheckMolopt' + str(ind) + '.sdf'): shutil.move('CheckMolopt' + str(ind) + '.sdf', 'dft_result') #if os.path.isfile('CheckMolopt'+str(ind)+'.com'): # shutil.move('CheckMolopt'+str(ind)+'.com', 'dft_result') #if os.path.isfile('CheckMolopt'+str(ind)+'.log'): # shutil.move('CheckMolopt'+str(ind)+'.log', 'dft_result') #if os.path.isfile('CheckMolopt'+str(ind)+'.chk'): # os.remove('CheckMolopt'+str(ind)+'.chk') except: os.chdir(cd_path) wavelength = None if os.path.isfile('CheckMolopt' + str(ind) + '.sdf'): os.remove('CheckMolopt' + str(ind) + '.sdf') if os.path.isfile('CheckMol' + str(ind) + '.sdf'): os.remove('CheckMol' + str(ind) + '.sdf') else: wavelength = None if os.path.isfile('CheckMolopt' + str(ind) + '.sdf'): os.remove('CheckMolopt' + str(ind) + '.sdf') if os.path.isfile('CheckMol' + str(ind) + '.sdf'): os.remove('CheckMol' + str(ind) + '.sdf') if wavelength != None and wavelength != []: wavenum = wavelength[0] intensity = outdic['uv'][1][0] deen = outdic['deen'] gap = outdic['gap'] wl_list = outdic['uv'][0] intensity_list = outdic['uv'][1] else: wavenum = -1000 if s1_wavelength != None and s1_wavelength != []: s1_wavenum = s1_wavelength[0] s1_strength = outdic[ 'S1 Wavelength and Oscillator strengths'][1][0] s1_wl_list = outdic[ 'S1 Wavelength and Oscillator strengths'][0] s1_str_list = outdic[ 'S1 Wavelength and Oscillator strengths'][1] else: s1_wavenum = -1000 else: wavenum = -1000 score.append(wavenum) score.append(new_compound[0]) score.append(rank) score.append(intensity) score.append(deen) score.append(gap) score.append(wl_list) score.append(intensity_list) score.append(ind) score.append(mol_weight) score.append(logP) score.append(SA_score) score.append(dp) score.append(s1_wavenum) #flour score.append(s1_strength) score.append(s1_wl_list) score.append(s1_str_list) comm.send(score, dest=0, tag=DONE) simulation_fi_time = time.time() - simulation_time print("simulation_fi_time:", simulation_fi_time) if tag == EXIT: MPI.Abort(MPI.COMM_WORLD) comm.send( [-1000, '', 0, 0, 0, 0, [], [], ind, 0, 0, 0, 0, -1000, 0, [], []], dest=0, tag=EXIT)
def CFD(xyzL=[1.5E-003, 1.5E-003, 2.50E-003], g=9.81, ncxyz=[8, 8, 8], npxyz=[1, 1, 1], Nsteps=101): #initialise MPI and CPL comm = MPI.COMM_WORLD CPL = CPL() MD_COMM = CPL.init(CPL.CFD_REALM) nprocs_realm = MD_COMM.Get_size() ## Parameters of the cpu topology (cartesian grid) npxyz = np.array(npxyz, order='F', dtype=np.int32) NProcs = np.product(npxyz) xyzL = np.array(xyz, order='F', dtype=np.float64) xyz_orig = np.array([0.0, 0.0, 0.0], order='F', dtype=np.float64) ncxyz = np.array(ncxyz, order='F', dtype=np.int32) if (nprocs_realm != NProcs): print("Non-coherent number of processes in MD ", nprocs_realm, " no equal to ", npxyz[0], " X ", npxyz[1], " X ", npxyz[2]) MPI.Abort(errorcode=1) #Setup coupled simulation cart_comm = MD_COMM.Create_cart([npxyz[0], npxyz[1], npxyz[2]]) CPL.setup_cfd(cart_comm, xyzL, xyz_orig, ncxyz) #Get constraint region cnst_limits = CPL.get_cnst_limits() cnst_portion = CPL.my_proc_portion(cnst_limits) [cnst_ncxl, cnst_ncyl, cnst_nczl] = CPL.get_no_cells(cnst_portion) #Get overlap region olap_limits = CPL.get_olap_limits() BC_limits = np.array([ olap_limits[0], olap_limits[1], olap_limits[2], olap_limits[3], olap_limits[4], olap_limits[5] ], dtype=np.int32) BC_portion = CPL.my_proc_portion(BC_limits) [BC_ncxl, BC_ncyl, BC_nczl] = CPL.get_no_cells(BC_portion) #Allocate send and recv arrays recv_array = np.zeros((4, BC_ncxl, BC_ncyl, BC_nczl), order='F', dtype=np.float64) send_array = np.zeros((9, cnst_ncxl, cnst_ncyl, cnst_nczl), order='F', dtype=np.float64) for time in range(Nsteps): # send data to update send_array[2, :, :, :] = -5.9490638385009208e-08 * g # * mi CPL.send(send_array, cnst_portion) # recv data and plot recv_array, ierr = CPL.recv(recv_array, BC_portion) print(time) CPL.finalize() MPI.Finalize()
len_lists_to_send = 5000 # DISTANCE LISTS if rank == 0: # RUN PROGRAM distance_list = load(distance_list_path) shuffle(distance_list) shuffle(distance_list) dists = [] last_list = None for x in itertools.permutations(distance_list): dists.append(x) list_length = len(dists) if list_length >= len_lists_to_send: if last_list == dists: print ERROR_MESSAGE MPI.Abort() d = comm.recv(source=2, tag=1) if d: total_sent += list_length comm.send([dists, (rank, name)], dest=2, tag=2) p_2 = '[SENDING JOB TO ' + \ str(d[0])+' ON '+str(d[1])+'] ' p_3 = '[t_sent ' + str(total_sent) + '] ' last_list = dists dists = [] p_4 = '[list_len was ' + \ str(list_length)+'| now : '+str(len(dists))+']' print p_1 + p_2 + p_3 + p_4 else: print p_1 + '[NO ONE TO SEND TO]' # SHUTDOWN PROGRAM