def __read_input_file(fname): """Read runner input file""" with open(fname) as f: runner_dict = iprPy.tools.parseinput(f, allsingular=True) run_directory = os.path.abspath(runner_dict['run_directory']) orphan_directory = runner_dict.get( 'orphan_directory', os.path.join(os.path.dirname(run_directory), 'orphan')) dbase = iprPy.database_fromdict(runner_dict) return run_directory, orphan_directory, dbase
def __read_input_file(fname): """Read runner input file""" with open(fname) as f: build_dict = iprPy.tools.parseinput(f, allsingular=True) library_directory = os.path.abspath( build_dict.get('library_directory', os.path.join(os.path.dirname(iprPy.rootdir), 'library'))) dbase = iprPy.database_fromdict(build_dict) return library_directory, dbase
def main(*args): """Main function called when script is executed directly.""" # Read input script with open(args[0]) as f: input_dict = iprPy.tools.parseinput(f, singularkeys=singularkeys()) # Open database dbase = iprPy.database_fromdict(input_dict) # Pull out run_directory run_directory = input_dict.pop('run_directory') # Call prepare prepare(dbase, run_directory, **input_dict)
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 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)