rmd.filedump(run_specs, filename) rmd.init_stdout() # read settings # POSCAR if 'poscar' in run_specs: structure = rmd.get_structure(run_specs) elif os.path.isfile('../POSCAR'): structure = mg.Structure.from_file('../POSCAR') rmd.insert_elem_types(run_specs, structure) # INCAR incar = rmd.read_incar(run_specs) if os.path.isfile('../properties.json'): properties = rmd.fileload('../properties.json') if 'ISPIN' not in incar: if rmd.detect_is_mag(properties['mag']): incar.update({'ISPIN': 2}) else: incar.update({'ISPIN': 1}) # POTCAR dump rmd.write_potcar(run_specs) potcars = mg.io.vasp.Potcar.from_file('POTCAR') incar['ENCUT'] = rmd.get_max_ENMAX(potcars) NBANDS, basisfunctions_str = get_NBANDS_and_basisfunctions_str(potcars, structure) incar['NBANDS'] = NBANDS # KPOINTS
slice: [null, -4] The slice is applied to the volume and structure list. """ run_specs, filename = rmd.get_run_specs_and_filename() cwd = os.getcwd() rmd.chdir(rmd.get_run_dir(run_specs)) rmd.filedump(run_specs, filename) phonopy_specs = run_specs['phonopy'] phonopy_specs['dim'] = ' '.join(map(str, phonopy_specs['dim'])) incar = rmd.read_incar(run_specs) if os.path.isfile('../properties.json'): properties = rmd.fileload('../properties.json') if 'ISPIN' not in incar: if rmd.detect_is_mag(properties['mag']): incar.update({'ISPIN': 2}) else: incar.update({'ISPIN': 1}) # higher priority for run_specs if 'poscar' in run_specs: structure = rmd.get_structure(run_specs) elif os.path.isfile('../POSCAR'): structure = mg.Structure.from_file('../POSCAR') rmd.insert_elem_types(run_specs, structure) kpoints = rmd.read_kpoints(run_specs, structure)
is_well_fitted, V0, structure, is_mag = volume_fitting(structure, is_mag, fitting_results) if 'volume' in run_specs and 'rerun' in run_specs['volume'] and run_specs['volume']['rerun']: # possible next rounds while not is_well_fitted: V_begin = V0 * 9./10 V_end = V0 * 11./10 is_well_fitted, V0, structure, is_mag = volume_fitting(structure, is_mag, fitting_results) # pressure runs if 'pressure' in run_specs and run_specs['pressure']: pressure_params = run_specs['pressure'] p_begin = pressure_params['begin'] p_end = pressure_params['end'] V_sample_point_num = pressure_params['sample_point_num'] params = rmd.fileload('fitting_params.json') from scipy import optimize def pressure_func(V): return pv.fitting.vinet_p(V, params['V0'], params['B0'], params['B0_prime']) - p0 V_list = [] for p0 in [p_begin, p_end]: V_list.append(optimize.fsolve(pressure_func, structure.volume)[0]) V_begin, V_end = V_list is_well_fitted, V0, structure, is_mag = volume_fitting(structure, is_mag, fitting_results) # equilibrium volume run structure.scale_lattice(V0) structure.to(filename='POSCAR') incar.write_file('INCAR') kpoints.write_file('KPOINTS') rmd.write_potcar(run_specs)
run_specs, filename = rmd.get_run_specs_and_filename() rmd.chdir(rmd.get_run_dir(run_specs)) phonopy_specs = run_specs['phonopy'] phonopy_specs['dim'] = ' '.join(map(str, phonopy_specs['dim'])) phonopy_specs['mp'] = ' '.join(map(str, phonopy_specs['mp'])) phonopy_specs['tmax'] = str(phonopy_specs['tmax']) phonopy_specs['tstep'] = str(phonopy_specs['tstep']) run_volume_dirname = phonopy_specs['volumes_and_structures']['from']\ if 'volumes_and_structures' in phonopy_specs and \ 'from' in phonopy_specs['volumes_and_structures'] and \ phonopy_specs['volumes_and_structures']['from'] else 'run_volume' if isinstance(run_volume_dirname, str): fitting_results = rmd.fileload(os.path.join('..', run_volume_dirname, 'fitting_results.json'))[-1] volume = fitting_results['volume'] energy = fitting_results['energy'] elif isinstance(run_volume_dirname, list): volume = [] energy = [] for dirname in run_volume_dirname: fitting_results = rmd.fileload(os.path.join('..', dirname, 'fitting_results.json'))[-1] volume.extend(fitting_results['volume']) energy.extend(fitting_results['energy']) idx_slice = phonopy_specs['volumes_and_structures']['slice'] if \ 'volumes_and_structures' in phonopy_specs and \ 'slice' in phonopy_specs['volumes_and_structures'] and \ phonopy_specs['volumes_and_structures']['slice'] else [None] * 2
would use to actually run the routine script run_elastic_single.py before this. """ run_specs, filename = rmd.get_run_specs_and_filename() rmd.chdir(rmd.get_run_dir(run_specs)) cryst_sys = run_specs['elastic']['cryst_sys'] test_type_input = run_specs['elastic']['test_type'] incar = rmd.read_incar(run_specs) if 'ISPIN' in incar: is_mag = incar['ISPIN'] == 2 elif os.path.isfile(('../properties.json')): properties = rmd.fileload('../properties.json') is_mag = rmd.detect_is_mag(properties['mag']) else: is_mag = False test_type_list, strain_list, delta_list = rmd_e.get_test_type_strain_delta_list(cryst_sys) for test_type, strain, delta in zip(test_type_list, strain_list, delta_list): if test_type == test_type_input: rmd.chdir(test_type) energy = np.zeros(len(delta)) mag = np.zeros(len(delta)) for ind, value in enumerate(delta): rmd.chdir(str(value)) oszicar = mg.io.vasp.Oszicar('OSZICAR') energy[ind] = oszicar.final_energy if is_mag:
file you used to actually run the routine script run_elastic_stress_strain.py before this. """ # pre-config run_specs, filename = rmd.get_run_specs_and_filename() rmd.chdir(rmd.get_run_dir(run_specs)) rmd.filedump(run_specs, filename) rmd.init_stdout() # read settings structure = rmd.get_structure(run_specs) # elastic strain_list = [i for i in rmd.fileload('strain_list.json')] stress_list = [] for idx, strain in enumerate(strain_list): vasprun = mg.io.vasp.Vasprun(str(idx) + '/vasprun.xml') stress_list.append( elasticity.stress.Stress(vasprun.ionic_steps[-1]['stress']) / -10) rmd.filedump([i.tolist() for i in stress_list], 'stress_list.json') elastic_tensor = elasticity.elastic.ElasticTensor.from_strain_stress_list( strain_list, stress_list).voigt elastic_tensor_df = pd.DataFrame(elastic_tensor, index=range(1, 7), columns=range(1, 7)) elastic_tensor_df.to_csv('elastic_tensor.csv') pd.set_option('display.float_format', lambda x: '%.6f' % x) print(elastic_tensor_df)
range. A second run is done using those volume values. the tag 'skip_test_run' tells the code to just use the fitting_params.json in the working directory without doing the test run. """ run_specs, filename = rmd.get_run_specs_and_filename() rmd.chdir(rmd.get_run_dir(run_specs)) rmd.filedump(run_specs, filename) rmd.init_stdout() incar = rmd.read_incar(run_specs) is_properties = None if os.path.isfile(('../properties.json')): is_properties = True properties = rmd.fileload('../properties.json') if 'ISPIN' in incar: is_mag = incar['ISPIN'] == 2 elif is_properties: is_mag = rmd.detect_is_mag(properties['mag']) if is_mag: incar.update({'ISPIN': 2}) else: incar.update({'ISPIN': 1}) else: is_mag = False # higher priority for run_specs if 'poscar' in run_specs: structure = rmd.get_structure(run_specs)
python INPUT/process_elastic_stress_strain.py INPUT/run_elastic_stress_strain.yaml to read a specs file at INPUT/run_elastic_stress_strain.yaml, which is the file you used to actually run the routine script run_elastic_stress_strain.py before this. """ # pre-config run_specs, filename = rmd.get_run_specs_and_filename() rmd.chdir(rmd.get_run_dir(run_specs)) rmd.filedump(run_specs, filename) rmd.init_stdout() # read settings structure = rmd.get_structure(run_specs) # elastic strain_list = [i for i in rmd.fileload('strain_list.json')] stress_list = [] for idx, strain in enumerate(strain_list): vasprun = mg.io.vasp.Vasprun(str(idx) + '/vasprun.xml') stress_list.append(elasticity.stress.Stress(vasprun.ionic_steps[-1]['stress'])/-10) rmd.filedump([i.tolist() for i in stress_list], 'stress_list.json') elastic_tensor = elasticity.elastic.ElasticTensor.from_strain_stress_list(strain_list, stress_list) elastic_tensor_df = pd.DataFrame(elastic_tensor, index=range(1, 7), columns=range(1, 7)) elastic_tensor_df.to_csv('elastic_tensor.csv') pd.set_option('display.float_format', lambda x: '%.6f' % x) print(elastic_tensor_df)
plt.savefig(test_type + '.pdf') plt.close() fitting_results['params'] = fitting_results['params'].tolist() fitting_results.pop('fitted_data') fitting_results.pop('ax') fitting_results['delta'] = delta.tolist() fitting_results['energy'] = energy.tolist() fitting_results['mag'] = mag.tolist() rmd.filedump(fitting_results, 'fitting_results.json') # higher level fitting_results.json fitting_results_summary[test_type] = fitting_results rmd.filedump(fitting_results_summary, '../fitting_results.json') shutil.copy(test_type + '.pdf', '..') os.chdir('..') # fitting_results_summary['c11+2c12'] = {} # fitting_results_summary['c11+2c12']['params'] = [properties['B0'] * structure.volume / 160.2 * 9/2.] combined_econst_array = [ fitting_results_summary[test_type]['params'][0] for test_type in test_type_list ] combined_econst_array = np.array( combined_econst_array) * 160.2 / structure.volume solved = rmd_e.solve(cryst_sys, combined_econst_array) rmd.filedump(solved, 'elastic.json') if os.path.isfile('../properties.json'): properties = rmd.fileload('../properties.json') properties['elastic'] = solved rmd.filedump(properties, '../properties.json')
to read a specs file at INPUT/run_elastic_single.yaml, which is the file you would use to actually run the routine script run_elastic_single.py and the process script process_elastic_single.py for all the independent strain sets before this. """ run_specs, filename = rmd.get_run_specs_and_filename() rmd.chdir(rmd.get_run_dir(run_specs)) cryst_sys = run_specs['elastic']['cryst_sys'] is_properties = None if os.path.isfile(('../properties.json')): is_properties = True properties = rmd.fileload('../properties.json') # higher priority for run_specs if 'poscar' in run_specs: structure = rmd.get_structure(run_specs) elif os.path.isfile('../POSCAR'): structure = mg.Structure.from_file('../POSCAR') rmd.insert_elem_types(run_specs, structure) test_type_list, strain_list, delta_list = rmd_e.get_test_type_strain_delta_list(cryst_sys) fitting_results_summary = rmd.fileload('fitting_results.json') # fitting_results_summary['c11+2c12'] = {} # fitting_results_summary['c11+2c12']['params'] = [properties['B0'] * structure.volume / 160.2 * 9/2.] combined_econst_array = [fitting_results_summary[test_type]['params'][0] for test_type in test_type_list] combined_econst_array = np.array(combined_econst_array) * 160.2 / structure.volume
structure_copy = structure.copy() structure_copy.modify_lattice(lattice_modified) structure_copy.to(filename='POSCAR') rmd.write_potcar(run_specs) rmd.run_vasp() oszicar = mg.io.vasp.Oszicar('OSZICAR') energy[ind] = oszicar.final_energy if is_mag: mag[ind] = oszicar.ionic_steps[-1]['mag'] os.chdir('..') fitting_results = pydass_vasp.fitting.curve_fit(rmd_e.central_poly, delta, energy, plot=True) plt.savefig(test_type + '.pdf') plt.close() fitting_results['params'] = fitting_results['params'].tolist() fitting_results.pop('fitted_data') fitting_results.pop('ax') fitting_results['delta'] = delta.tolist() fitting_results['energy'] = energy.tolist() fitting_results['mag'] = mag.tolist() rmd.filedump(fitting_results, 'fitting_results.json') # higher level fitting_results.json if os.path.isfile('../fitting_results.json'): fitting_results_summary = rmd.fileload('../fitting_results.json') else: fitting_results_summary = {} fitting_results_summary[test_type] = fitting_results rmd.filedump(fitting_results_summary, '../fitting_results.json') shutil.copy(test_type + '.pdf', '..') os.chdir('..')
rmd.run_vasp() oszicar = mg.io.vasp.Oszicar('OSZICAR') energy[ind] = oszicar.final_energy if is_mag: mag[ind] = oszicar.ionic_steps[-1]['mag'] os.chdir('..') fitting_results = pydass_vasp.fitting.curve_fit(rmd_e.central_poly, delta, energy, plot=True) plt.savefig(test_type + '.pdf') plt.close() fitting_results['params'] = fitting_results['params'].tolist() fitting_results.pop('fitted_data') fitting_results.pop('ax') fitting_results['delta'] = delta.tolist() fitting_results['energy'] = energy.tolist() fitting_results['mag'] = mag.tolist() rmd.filedump(fitting_results, 'fitting_results.json') # higher level fitting_results.json if os.path.isfile('../fitting_results.json'): fitting_results_summary = rmd.fileload( '../fitting_results.json') else: fitting_results_summary = {} fitting_results_summary[test_type] = fitting_results rmd.filedump(fitting_results_summary, '../fitting_results.json') shutil.copy(test_type + '.pdf', '..') os.chdir('..')
if 'volume' in run_specs and 'rerun' in run_specs['volume'] and run_specs[ 'volume']['rerun']: # possible next rounds while not is_well_fitted: V_begin = V0 * 9. / 10 V_end = V0 * 11. / 10 is_well_fitted, V0, structure, is_mag = volume_fitting( structure, is_mag, fitting_results) # pressure runs if 'pressure' in run_specs and run_specs['pressure']: pressure_params = run_specs['pressure'] p_begin = pressure_params['begin'] p_end = pressure_params['end'] V_sample_point_num = pressure_params['sample_point_num'] params = rmd.fileload('fitting_params.json') from scipy import optimize def pressure_func(V): return pv.fitting.vinet_p(V, params['V0'], params['B0'], params['B0_prime']) - p0 V_list = [] for p0 in [p_begin, p_end]: V_list.append(optimize.fsolve(pressure_func, structure.volume)[0]) V_begin, V_end = V_list is_well_fitted, V0, structure, is_mag = volume_fitting( structure, is_mag, fitting_results) # equilibrium volume run structure.scale_lattice(V0)