def main(): # read in the .json file as an command line argument? mp_properties = read_mp_properties('test_120_materials.json') # try to create folder 'property_calculations' # if it already exists, continue with the program try: os.mkdir('property_calculations') except: pass # primary loop for MD try: for id, cif in enumerate(mp_properties['cif']): f = open("tmp_cif.cif", "w+") f.write(cif) f.close() atoms = ase.io.read("tmp_cif.cif", None) print("\n \n \nRUNNING MOLECULAR DYNAMICS") try: md.run_md(atoms, str(id)) except Exception as e: print("\n ERROR IN RUNNING MD \n") print("Exception: ", e) os.remove("tmp_cif.cif") except KeyboardInterrupt: pass
def equilibriate(self, struct=None, top=None, sub=None, **args): """ Equilibriates (thermalizes) the structure stored in self.universe. takes the universe structure, inputs it to md, performs an equilibriation run, and read the result back into the universe. The equilibriated atomic state can then be used at the starting state the md sampling run, and for the langevin step. The MD is typically performed with position restraints on the protein. The equilibriated position are also written to the current_timestep. @precondition: self.universe contains an atomic state. @postcondition: self.universe now contains an equilbriated state. subsystems are notified. equililibriated state is written to current_timestep. """ logging.debug( \ "struct = {}, top = {}, sub = {}, args = {}".format( \ struct, top , sub , args)) result = None if struct is None or top is None: logging.info("performing equilibriation for self.universe") with self.setup_equilibriate() as eqsetup: mdres = md.run_md(eqsetup.dirname, **eqsetup) self.universe.load_new(mdres.structs[0]) else: logging.info("performing equilibriation for solvated struct, top") result = self.setup_equilibriate(struct, top) mdres = md.run_md(result.dirname, **result) result["struct"] = mdres.structs[0] result["sub"] = sub self.universe.atoms.positions = util.stripped_positions( mdres.structs[0], sub) self.current_timestep.atomic_equilibriated_positions = self.universe.atoms.positions [s.equilibriated() for s in self.subsystems] return result
def equilibrate(self, struct=None, top=None, sub=None, **args): """ Equilibrates (thermalizes) the structure stored in self.universe. takes the universe structure, inputs it to md, performs an equilibration run, and read the result back into the universe. The equilibrated atomic state can then be used at the starting state the md sampling run, and for the langevin step. The MD is typically performed with position restraints on the protein. The equilibrated position are also written to the current_timestep. @precondition: self.universe contains an atomic state. @postcondition: self.universe now contains an equilbriated state. subsystems are notified. equililibriated state is written to current_timestep. """ logging.debug( \ "struct = {}, top = {}, sub = {}, args = {}".format( \ struct, top , sub , args)) result = None if struct is None or top is None: logging.info("performing equilibration for self.universe") with self.setup_equilibrate() as eqsetup: mdres = md.run_md(eqsetup.dirname, **eqsetup) self.universe.load_new(mdres.structs[0]) else: logging.info("performing equilibration for solvated struct, top") result = self.setup_equilibrate(struct, top) mdres = md.run_md(result.dirname, **result) result["struct"] = mdres.structs[0] result["sub"] = sub self.universe.atoms.positions = util.stripped_positions(mdres.structs[0], sub) self.current_timestep.atomic_equilibrated_positions = self.universe.atoms.positions [s.equilibrated() for s in self.subsystems] return result
def md(self, struct=None, top=None, sub=None, **args): """ Perform a set of molecular dynamics runs using the atomic state of self.universe as the starting structure. The state of self.universe is NOT modified. @precondition: self.universe contains a valid atomic state. @postcondition: self.cg_positions, self.cg_forces, self.cg_velocities[:] are populated with statistics collected from the md runs. """ logging.debug( \ "struct = {}, top = {}, sub = {}, args = {}".format( \ struct, top , sub , args)) with self.setup_md(struct, top) as mdsetup: mdres = md.run_md(mdsetup.dirname, **mdsetup) self._processes_trajectories(mdres.trajectories, sub)
# properties of copper atoms_l = [] #atoms_l.append(bulk('Ar', 'fcc', a=5.26, cubic=True)) atoms_l.append(bulk('Cu', 'fcc', a=3.6, cubic=True)) #atoms = bulk('Ar', 'fcc', a=5.26, cubic=True) #atoms = bulk('Cu', 'fcc', a=3.6, cubic=True) settings = read_settings_file('acc_test_setting.json') atoms_list = [] for atoms in atoms_l: if settings['vol_relax']: cell = np.array(atoms.get_cell()) P = settings['LC_steps'] for i in range(-P, 1 + P): atoms_v = copy.deepcopy(atoms) atoms_v.set_cell(cell * (1 + i * settings['LC_mod'])) atoms_list.append(atoms_v) else: atoms_list.append(atoms) print(atoms_list) for i, a in enumerate(atoms_list): try: md.run_md(a, a.get_chemical_symbols()[0] + str(i), 'acc_test_setting.json') except Exception as e: print("Run broke: " + str(e))
def main(): # don't allow Python libraries to start spanning threads # over the available cores supercomputer_init() # set up variables for parallelization comm = MPI.COMM_WORLD rank = comm.Get_rank() size = comm.Get_size() # read materials from settings file settings = read_settings_file() mp_properties = read_mp_properties(settings['materials']) # try to create folder 'property_calculations' # if it already exists, continue with the program try: os.mkdir('property_calculations') except: pass # try to create folder 'trajectory_files' # if it already exists, continue with the program try: os.mkdir('trajectory_files') except: pass # create one list of all atom objects in data-file atoms_list = [] for cif in mp_properties['cif']: f = open('tmp'+str(rank)+'.cif', 'w+') f.write(cif) f.close() atoms = ase.io.read('tmp'+str(rank)+'.cif') lengths = atoms.get_cell_lengths_and_angles()[0:3] angles = atoms.get_cell_lengths_and_angles()[3:6] if settings['cubic_only']: if len(set(lengths)) == 1 and len(set(angles)) == 1 and angles[0] == 90: if settings['vol_relax']: cell = np.array(atoms.get_cell()) P = settings['LC_steps'] for i in range(-P,1+P): atoms_v = copy.deepcopy(atoms) atoms_v.set_cell(cell*(1+i*settings['LC_mod'])) atoms_list.append(atoms_v) else: atoms_list.append(atoms) else: if settings['vol_relax']: cell = np.array(atoms.get_cell()) P = settings['LC_steps'] for i in range(-P,1+P): atoms_v = copy.deepcopy(atoms) atoms_v.set_cell(cell*(1+i*settings['LC_mod'])) atoms_list.append(atoms_v) else: atoms_list.append(atoms) print("Created atoms list of length " + str(len(atoms_list))) os.remove("tmp"+str(rank)+".cif") # Run the molecular dynamics in parallell (might want to # improve it) if rank == 0: jobs = np.arange(0, len(atoms_list), dtype=np.int) job_array = np.array_split(jobs, size) #print("we have", size, " processes.") for i in range(0, size): comm.isend(len(job_array[i]), dest=i, tag=i) comm.Isend([job_array[i],MPI.INT], dest=i, tag=i) # how do I send in the correct atoms-object to md_run? l = comm.recv(source=0, tag=rank) data = np.ones(l,dtype=np.int) comm.Recv([data,MPI.INT],source=0, tag=rank) for id in data: #print("ID: ", id) #print(atoms) try: md.run_md(atoms_list[id], str(id).zfill(4), 'settings.json') except Exception as e: print("Run broke!:"+str(e)) print("Happened for ID:" + str(id).zfill(4)) comm.Barrier()
import md import sys import os md.run_md() if not os.path.exists('cu.traj'): sys.exit(1)