def main(*args): calculation = iprPy.Calculation(__calc_style__) with open(args[0]) as f: prepare_dict = read_input(f) #open database dbase = iprPy.database_fromdict(prepare_dict) #Build record_df record_df = build_record_df(dbase, __record_style__) #Loop over all potentials for pot_record in iprPy.prepare.ipotentials( dbase, element=prepare_dict['potential_element'], name=prepare_dict['potential_name'], pair_style=prepare_dict['potential_pair_style']): potential = lmp.Potential(pot_record.content) pot_tar = dbase.get_tar(pot_record) #Loop over all prototypes for proto_record in iprPy.prepare.iprototypes( dbase, natypes=prepare_dict['prototype_natypes'], name=prepare_dict['prototype_name'], spacegroup=prepare_dict['prototype_spacegroup'], crystalfamily=prepare_dict['prototype_crystalfamily'], pearson=prepare_dict['prototype_Pearsonsymbol']): #Iterate over all combinations of potentials, prototypes and symbols for symbols in iprPy.prepare.isymbolscombos( proto_record, pot_record): #Create calc_key calc_key = str(uuid.uuid4()) #Define values for calc_*.in file calc_dict = {} calc_dict['lammps_command'] = prepare_dict['lammps_command'] calc_dict['mpi_command'] = prepare_dict['mpi_command'] calc_dict['potential_file'] = pot_record.name + '.xml' calc_dict['potential_dir'] = pot_record.name calc_dict[ 'load'] = 'system_model ' + proto_record.name + '.xml' calc_dict['load_options'] = '' calc_dict['symbols'] = ' '.join(symbols) calc_dict['box_parameters'] = '' calc_dict['x_axis'] = '' calc_dict['y_axis'] = '' calc_dict['z_axis'] = '' calc_dict['atomshift'] = '' calc_dict['sizemults'] = prepare_dict['sizemults'] calc_dict['length_unit'] = prepare_dict['length_unit'] calc_dict['pressure_unit'] = prepare_dict['pressure_unit'] calc_dict['energy_unit'] = prepare_dict['energy_unit'] calc_dict['force_unit'] = prepare_dict['force_unit'] calc_dict['minimum_r'] = prepare_dict['minimum_r'] calc_dict['maximum_r'] = prepare_dict['maximum_r'] calc_dict['number_of_steps_r'] = prepare_dict[ 'number_of_steps_r'] #Build inputfile by filling in calculation's template inputfile = iprPy.tools.filltemplate(calculation.template, calc_dict, '<', '>') #Read inputfile to build input_dict input_dict = calculation.read_input(inputfile, calc_key) #Define additional input_dict terms input_dict['potential'] = potential input_dict['load_file'] = proto_record.content iprPy.input.system_family(input_dict) #Build incomplete record new_record = iprPy.Record( name=calc_key, content=calculation.data_model(input_dict).xml(), style=__record_style__) #Check if record is new if is_new(record_df, new_record): #Add record to database dbase.add_record(record=new_record) #Generate calculation folder calc_directory = os.path.join( prepare_dict['run_directory'], calc_key) os.makedirs(calc_directory) #Save inputfile to calculation folder with open( os.path.join(calc_directory, 'calc_' + __calc_style__ + '.in'), 'w') as f: f.write(inputfile) #Add calculation files to calculation folder for calc_file in calculation.files: shutil.copy(calc_file, calc_directory) #Add potential record file to calculation folder with open( os.path.join(calc_directory, pot_record.name + '.xml'), 'w') as f: f.write(pot_record.content) #Extract potential's tar files to calculation folder pot_tar.extractall(calc_directory) #Add prototype record file to calculation folder with open( os.path.join(calc_directory, proto_record.name + '.xml'), 'w') as f: f.write(proto_record.content)
def main(*args): calculation = iprPy.Calculation(__calc_style__) with open(args[0]) as f: prepare_dict = read_input(f) #open database dbase = iprPy.database_fromdict(prepare_dict) #Build record_df record_df = build_record_df(dbase, __record_style__) #Build potential dictionaries (single dbase access) pot_record_dict = {} pot_tar_dict = {} for pot_record in dbase.iget_records(style='LAMMPS-potential'): pot_record_dict[pot_record.name] = pot_record #Load E_vs_r_scan records for parent_record in iprPy.prepare.icalculations( dbase, record_style='calculation-cohesive-energy-relation', symbol=prepare_dict['symbol_name'], prototype=prepare_dict['prototype_name'], potential=prepare_dict['potential_name']): parent_dict = parent_record.todict() #Load potential pot_record = pot_record_dict[parent_dict['potential_id']] potential = lmp.Potential(pot_record.content) #Get pot_tar from dbase only once per potential if parent_dict['potential_id'] in pot_tar_dict: pot_tar = pot_tar_dict[parent_dict['potential_id']] else: pot_tar = dbase.get_tar(pot_record) pot_tar_dict[parent_dict['potential_id']] = pot_tar #Loop over number_min_states for i in xrange(parent_dict['number_min_states']): if i == 0: load_options = 'key minimum-atomic-system' else: load_options = 'key minimum-atomic-system index ' + str(i) #Loop over strainrange values for strain in iprPy.tools.iaslist(prepare_dict['strainrange']): #Create calc_key calc_key = str(uuid.uuid4()) #Define values for calc_*.in file calc_dict = {} calc_dict['lammps_command'] = prepare_dict['lammps_command'] calc_dict['mpi_command'] = prepare_dict['mpi_command'] calc_dict['potential_file'] = pot_record.name + '.xml' calc_dict['potential_dir'] = pot_record.name calc_dict[ 'load'] = 'system_model ' + parent_record.name + '.xml' calc_dict['load_options'] = load_options calc_dict['symbols'] = '' calc_dict['box_parameters'] = '' calc_dict['x_axis'] = '' calc_dict['y_axis'] = '' calc_dict['z_axis'] = '' calc_dict['atomshift'] = '' calc_dict['sizemults'] = prepare_dict['sizemults'] calc_dict['length_unit'] = prepare_dict['length_unit'] calc_dict['pressure_unit'] = prepare_dict['pressure_unit'] calc_dict['energy_unit'] = prepare_dict['energy_unit'] calc_dict['force_unit'] = prepare_dict['force_unit'] calc_dict['strainrange'] = strain calc_dict['energytolerance'] = prepare_dict['energytolerance'] calc_dict['forcetolerance'] = prepare_dict['forcetolerance'] calc_dict['maxiterations'] = prepare_dict['maxiterations'] calc_dict['maxevaluations'] = prepare_dict['maxevaluations'] calc_dict['maxatommotion'] = prepare_dict['maxatommotion'] #Build inputfile by filling in calculation's template inputfile = iprPy.tools.filltemplate(calculation.template, calc_dict, '<', '>') #Read inputfile to build input_dict input_dict = calculation.read_input(inputfile, calc_key) #Define additional input_dict terms input_dict['potential'] = potential input_dict['load_file'] = parent_record.content iprPy.input.system_family(input_dict) #Build incomplete record new_record = iprPy.Record( name=calc_key, content=calculation.data_model(input_dict).xml(), style=__record_style__) #Check if record is new if is_new(record_df, new_record): #Add record to database dbase.add_record(record=new_record) #Generate calculation folder calc_directory = os.path.join( prepare_dict['run_directory'], calc_key) os.makedirs(calc_directory) #Save inputfile to calculation folder with open( os.path.join(calc_directory, 'calc_' + __calc_style__ + '.in'), 'w') as f: f.write(inputfile) #Add calculation files to calculation folder for calc_file in calculation.files: shutil.copy(calc_file, calc_directory) #Add potential record file to calculation folder with open( os.path.join(calc_directory, pot_record.name + '.xml'), 'w') as f: f.write(pot_record.content) #Extract potential's tar files to calculation folder pot_tar.extractall(calc_directory) #Add parent record file to calculation folder with open( os.path.join(calc_directory, parent_record.name + '.xml'), 'w') as f: f.write(parent_record.content)
def prepare(dbase, run_directory, **kwargs): """ High-throughput prepare function for the calculation. Parameters ---------- dbase : iprPy.Database The database to access and create new records for. run_directory : str The path to the local directory where the prepared calculation instances will be placed. **kwargs Arbitrary keyword arguments. """ # Initialize Calculation instance calculation = iprPy.Calculation(calc_style) # Build record_df record_df = dbase.get_records_df(style=record_style, full=False, flat=True) # Build defect model record dictionary and df (single dbase access) defect_record_dict = {} defect_record_df = [] for defect_record in dbase.iget_records(style='dislocation_monopole'): defect_record_dict[defect_record.name] = defect_record defect_record_df.append(defect_record.todict()) defect_record_df = pd.DataFrame(defect_record_df) # Limit by defect name if 'dislocation_name' in kwargs: defect_names = iprPy.tools.aslist(kwargs['dislocation_name']) defect_selection = defect_record_df.id.isin(defect_names) defect_record_df = defect_record_df[defect_selection] # Get parent records if 'parent_records' in kwargs: parent_records = kwargs['parent_records'] else: parent_records = iprPy.prepare.icalculations(dbase, record_style = 'calculation_dislocation_Peierls_Nabarro', symbol = kwargs.get('symbol_name', None), family = kwargs.get('family_name', None), potential = kwargs.get('potential_name', None)) load_record_dict = {} gamma_record_dict = {} # Loop over parent records for parent_record in parent_records: parent_dict = parent_record.todict() # Get load_record from dbase only once per file load_record_key = os.path.splitext(parent_dict['load_file'])[0] if load_record_key in load_record_dict: load_record = load_record_dict[load_record_key] else: load_record = dbase.get_record(name=load_record_key) load_record_dict[load_record_key] = load_record # Get gamma_record from dbase only once per file gamma_record_key = parent_dict['gammasurface_calc_key'] if gamma_record_key in gamma_record_dict: gamma_record = gamma_record_dict[gamma_record_key] else: gamma_record = dbase.get_record(name=gamma_record_key) gamma_record_dict[gamma_record_key] = gamma_record # Loop over defect model records with family name matching parent record matches = defect_record_df['family'] == parent_dict['family'] defect_keys = defect_record_df[matches].id.tolist() for defect_key in defect_keys: defect_record = defect_record_dict[defect_key] # Create calc_key calc_key = str(uuid.uuid4()) # Define values for calc_*.in file calc_dict = {} calc_dict['load_file'] = load_record.name+'.xml' calc_dict['load_style'] = 'system_model' calc_dict['load_content'] = load_record.content calc_dict['load_options'] = parent_dict['load_options'] calc_dict['dislocation_model'] = defect_record.name+'.xml' calc_dict['dislocation_content'] = defect_record.content calc_dict['gammasurface_model'] = gamma_record.name+'.xml' calc_dict['gammasurface_content'] = gamma_record.content calc_dict['peierlsnabarro_model'] = parent_record.name+'.xml' calc_dict['peierlsnabarro_content'] = parent_record.content for key in singularkeys(): if key in kwargs: calc_dict[key] = kwargs[key] # Build incomplete record input_dict = {} for key in calc_dict: if calc_dict[key] != '': input_dict[key] = deepcopy(calc_dict[key]) calculation.process_input(input_dict, calc_key, build=False) model = iprPy.buildmodel(record_style, 'calc_' + calc_style, input_dict) new_record = iprPy.Record(name=calc_key, content=model.xml(), style=record_style) # Check if record is new if new_record.isnew(record_df=record_df): # Assign '' to any unassigned keys for key in unusedkeys()+singularkeys()+multikeys(): if key not in calc_dict: calc_dict[key] = '' # Add record to database dbase.add_record(record=new_record) # Generate calculation folder calc_directory = os.path.join(run_directory, calc_key) os.makedirs(calc_directory) # Save inputfile to calculation folder inputfile = iprPy.tools.filltemplate(calculation.template, calc_dict, '<', '>') with open(os.path.join(calc_directory, 'calc_' + calc_style + '.in'), 'w') as f: f.write(inputfile) # Add calculation files to calculation folder for calc_file in calculation.files: shutil.copy(calc_file, calc_directory) # Add load record file to calculation folder with open(os.path.join(calc_directory,load_record.name+'.xml'), 'w') as f: f.write(load_record.content) # Add gamma record file to calculation folder with open(os.path.join(calc_directory, gamma_record.name+'.xml'), 'w') as f: f.write(gamma_record.content) # Add parent record file to calculation folder with open(os.path.join(calc_directory, parent_record.name+'.xml'), 'w') as f: f.write(parent_record.content) # Add defect record file to calculation folder with open(os.path.join(calc_directory, defect_record.name+'.xml'), 'w') as f: f.write(defect_record.content)
def main(*args): calculation = iprPy.Calculation(__calc_style__) with open(args[0]) as f: prepare_dict = read_input(f) #open database dbase = iprPy.database_fromdict(prepare_dict) #Build record_df record_df = build_record_df(dbase, __record_style__) #Load relax_structure records for parent_record in iprPy.prepare.icalculations(dbase, record_style = 'calculation-structure-relax', symbol = prepare_dict['symbol_name'], prototype = 'A2--W--bcc', potential = prepare_dict['potential_name']): parent_dict = parent_record.todict() #Skip if strainrange not 1e-6 and calc_script not relax_structure if not np.isclose(parent_dict['strainrange'], 1e-6): continue if parent_dict['calc_script'] != 'calc_refine_structure': continue #Load potential, symbols, alat, and cohesive energy pot_record = dbase.get_record(name=parent_dict['potential_id'], style='LAMMPS-potential') potential = lmp.Potential(pot_record.content) pot_tar = dbase.get_tar(pot_record) symbols = parent_dict['symbols'] E_coh = parent_dict['E_cohesive'] alat = parent_dict['final_a'] #Loop over grain boundaries for x_axis_1, y_axis_1, z_axis_1, x_axis_2, y_axis_2, z_axis_2 in zip(prepare_dict['x_axis_1'], prepare_dict['y_axis_1'], prepare_dict['z_axis_1'], prepare_dict['x_axis_2'], prepare_dict['y_axis_2'], prepare_dict['z_axis_2']): #Create calc_key calc_key = str(uuid.uuid4()) #Define values for calc_*.in file calc_dict = {} calc_dict['lammps_command'] = prepare_dict['lammps_command'] calc_dict['mpi_command'] = prepare_dict['mpi_command'] calc_dict['potential_file'] = pot_record.name + '.xml' calc_dict['potential_dir'] = pot_record.name calc_dict['symbols'] = symbols * 3 calc_dict['alat'] = alat calc_dict['E_coh'] = E_coh calc_dict['x_axis_1'] = x_axis_1 calc_dict['y_axis_1'] = y_axis_1 calc_dict['z_axis_1'] = z_axis_1 calc_dict['x_axis_2'] = x_axis_2 calc_dict['y_axis_2'] = y_axis_2 calc_dict['z_axis_2'] = z_axis_2 calc_dict['x_stepsize'] = prepare_dict['x_stepsize'] calc_dict['z_stepsize'] = prepare_dict['z_stepsize'] calc_dict['length_unit'] = prepare_dict['length_unit'] calc_dict['pressure_unit'] = prepare_dict['pressure_unit'] calc_dict['energy_unit'] = prepare_dict['energy_unit'] calc_dict['force_unit'] = prepare_dict['force_unit'] #Build inputfile by filling in calculation's template inputfile = iprPy.tools.filltemplate(calculation.template, calc_dict, '<', '>') #Read inputfile to build input_dict input_dict = calculation.read_input(inputfile, calc_key) #Define additional input_dict terms input_dict['potential'] = potential input_dict['load_file'] = parent_record.content iprPy.input.system_family(input_dict) #Build incomplete record new_record = iprPy.Record(name=calc_key, content=calculation.data_model(input_dict).xml(), style=__record_style__) #Check if record is new if is_new(record_df, new_record): #Add record to database dbase.add_record(record=new_record) #Generate calculation folder calc_directory = os.path.join(prepare_dict['run_directory'], calc_key) os.makedirs(calc_directory) #Save inputfile to calculation folder with open(os.path.join(calc_directory, 'calc_' + __calc_style__ + '.in'), 'w') as f: f.write(inputfile) #Add calculation files to calculation folder for calc_file in calculation.files: shutil.copy(calc_file, calc_directory) #Add potential record file to calculation folder with open(os.path.join(calc_directory, pot_record.name+'.xml'), 'w') as f: f.write(pot_record.content) #Extract potential's tar files to calculation folder pot_tar.extractall(calc_directory) #Add parent record file to calculation folder with open(os.path.join(calc_directory, parent_record.name+'.xml'), 'w') as f: f.write(parent_record.content)