def my_error_function(variable_values): # Get rank from pool try: myrank = pool.rank except: myrank = 0 # FOR THE RELAXED STRUCTURE path = str(myrank) + '/relaxed' relaxed_job = gulp.job(path=path) ffio.write_forcefield_file(str(myrank) + '/FF', template, variable_values, verbose=False) relaxed_job.forcefield = str(myrank) + '/FF' relaxed_job.temporary_forcefield = False relaxed_job.structure = gt_relaxed_structure relaxed_job.pbc = True relaxed_job.options['relax_atoms'] = True relaxed_job.options['relax_cell'] = True relaxed_job.options['phonon_dispersion'] = True # Submit job and read output relaxed_job.options['phonon_dispersion_from'] = '0 0 0' relaxed_job.options['phonon_dispersion_to'] = '0.5 0.5 0' relaxed_job.write_script_file() relaxed_job.run(command='gulp') md_relaxed_disp_GS = gulp.read_phonon_dispersion(relaxed_job.path + '/out.gulp.disp') phon_error_relax = ezff.error_phonon_dispersion(md_relaxed_disp_GS, gt_relaxed_disp_GS, weights='acoustic') # Calculate errors in lattice constant and elastic modulus moduli = gulp.read_elastic_moduli(relaxed_job.path + '/' + relaxed_job.outfile) lattice = gulp.read_lattice_constant(relaxed_job.path + '/' + relaxed_job.outfile) a_latt_error = np.linalg.norm(lattice['err_abc'][0]) b_latt_error = np.linalg.norm(lattice['err_abc'][1]) modulus_error = np.linalg.norm((moduli[0, 0] * lattice['abc'][2] * 2.0 / 13.97) - gt_elastic_modulus) relaxed_job.cleanup() # FINISH RELAXED JOB # FOR THE COMPRESSED STRUCTURE path = str(myrank) + '/compressed' compressed_job = gulp.job(path=path) compressed_job.forcefield = str(myrank) + '/FF' compressed_job.temporary_forcefield = False compressed_job.structure = gt_compressed_structure compressed_job.pbc = True compressed_job.options['relax_atoms'] = True compressed_job.options['relax_cell'] = False compressed_job.options['phonon_dispersion'] = True # Submit job and read output compressed_job.options['phonon_dispersion_from'] = '0 0 0' compressed_job.options['phonon_dispersion_to'] = '0.5 0.5 0' compressed_job.write_script_file() compressed_job.run(command='gulp') md_compressed_disp_GS = gulp.read_phonon_dispersion(compressed_job.path + '/out.gulp.disp') phon_error_compressed = ezff.error_phonon_dispersion(md_compressed_disp_GS, gt_compressed_disp_GS, weights='acoustic') compressed_job.cleanup() # FINISH COMPRESSED JOB # FOR THE EXPANDED STRUCTURE path = str(myrank) + '/expanded' expanded_job = gulp.job(path=path) expanded_job.forcefield = str(myrank) + '/FF' expanded_job.temporary_forcefield = False expanded_job.structure = gt_expanded_structure expanded_job.pbc = True expanded_job.options['relax_atoms'] = True expanded_job.options['relax_cell'] = False expanded_job.options['phonon_dispersion'] = True # Submit job and read output expanded_job.options['phonon_dispersion_from'] = '0 0 0' expanded_job.options['phonon_dispersion_to'] = '0.5 0.5 0' expanded_job.write_script_file() expanded_job.run(command='gulp') md_expanded_disp_GS = gulp.read_phonon_dispersion(expanded_job.path + '/out.gulp.disp') phon_error_expanded = ezff.error_phonon_dispersion(md_expanded_disp_GS, gt_expanded_disp_GS, weights='acoustic') expanded_job.cleanup() # FINISH EXPANDED JOB return [ a_latt_error, b_latt_error, modulus_error, phon_error_relax, phon_error_compressed, phon_error_expanded ]
def my_error_function(variable_values): # Get rank from pool try: myrank = pool.rank except: myrank = 0 # FOR THE RELAXED STRUCTURE path = str(myrank) + '/relaxed' relaxed_job = gulp.job(path=path) relaxed_job.structure = gt_relax_structure relaxed_job.forcefield = ezff.generate_forcefield(template, variable_values, FFtype='SW') relaxed_job.options['pbc'] = True relaxed_job.options['relax_atoms'] = True relaxed_job.options['relax_cell'] = True relaxed_job.options['phonon_dispersion'] = True relaxed_job.options['phonon_dispersion_from'] = '0 0 0' relaxed_job.options['phonon_dispersion_to'] = '0.5 0.5 0' # Submit job and read output relaxed_job.run() # Read output from completed GULP job and cleanup job files md_relax_disp_GS = relaxed_job.read_phonon_dispersion() md_relaxed_moduli = relaxed_job.read_elastic_moduli() md_relaxed_structure = relaxed_job.read_structure() relaxed_job.cleanup() # FINISH RELAXED JOB # FOR THE COMPRESSED STRUCTURE path = str(myrank) + '/compressed' compressed_job = gulp.job(path=path) compressed_job.structure = gt_compressed_structure compressed_job.forcefield = ezff.generate_forcefield(template, variable_values, FFtype='SW') compressed_job.options['pbc'] = True compressed_job.options['relax_atoms'] = True compressed_job.options['relax_cell'] = False compressed_job.options['phonon_dispersion'] = True compressed_job.options['phonon_dispersion_from'] = '0 0 0' compressed_job.options['phonon_dispersion_to'] = '0.5 0.5 0' # Submit job and read output compressed_job.run() # Read output from completed GULP job and cleanup job files md_compressed_disp_GS = compressed_job.read_phonon_dispersion() compressed_job.cleanup() # FINISH COMPRESSED JOB # FOR THE EXPANDED STRUCTURE path = str(myrank) + '/expanded' expanded_job = gulp.job(path=path) expanded_job.structure = gt_expanded_structure expanded_job.forcefield = ezff.generate_forcefield(template, variable_values, FFtype='SW') expanded_job.options['pbc'] = True expanded_job.options['relax_atoms'] = True expanded_job.options['relax_cell'] = False expanded_job.options['phonon_dispersion'] = True expanded_job.options['phonon_dispersion_from'] = '0 0 0' expanded_job.options['phonon_dispersion_to'] = '0.5 0.5 0' # Submit job and read output expanded_job.run() # Read output from completed GULP job and cleanup job files md_expanded_disp_GS = expanded_job.read_phonon_dispersion() expanded_job.cleanup() # FINISH EXPANDED JOB # Compute 5 errors from the 3 GULP jobs error_abc, error_ang = ezff.error_lattice_constant(MD=md_relaxed_structure, GT=gt_relax_structure) a_lattice_error = np.linalg.norm( error_abc[0]) # Error in 'a' lattice constant b_lattice_error = np.linalg.norm( error_abc[1]) # Error in 'b' lattice constant md_c11 = md_relaxed_moduli[0][0, 0] * md_relaxed_structure.box[2, 2] * ( 2.0 / 13.97 ) # Extracting c11 for a bulk-like layered structure from the monolayer GULP calculation modulus_error = np.linalg.norm(md_c11 - gt_c11) phon_error_relaxed = ezff.error_phonon_dispersion(MD=md_relax_disp_GS, GT=gt_relax_disp_GS, weights='acoustic') phon_error_expanded = ezff.error_phonon_dispersion(MD=md_expanded_disp_GS, GT=gt_expanded_disp_GS, weights='acoustic') phon_error_compressed = ezff.error_phonon_dispersion( MD=md_compressed_disp_GS, GT=gt_compressed_disp_GS, weights='acoustic') return [ a_lattice_error, b_lattice_error, modulus_error, phon_error_relaxed, phon_error_compressed, phon_error_expanded ]