def initial_run(xcart_voids, ): """1. Run initial calculation""" if debug: cl = CalculationVasp() cl.read_poscar('1.POSCAR') cl.end = cl.init if xcart_voids: # read void coordinates cl.end = cl.end.add_atoms(xcart_voids, 'void') last_number = 0 else: files_yes = glob.glob('*yes.pickle') #get list of calculated yes files files_all = glob.glob('*.pickle') #get list of all calculated files """Find last yes pickle file""" if files_yes: yes_numbers = [int(file.split('-')[0]) for file in files_yes] all_numbers = [int(file.split('-')[0]) for file in files_all] last_yes_n = max(yes_numbers) last_number = max(all_numbers) last_yes_file = str(last_yes_n)+'-yes.pickle' printlog('Last calculation file is ', last_yes_file, imp = 'y') else: last_number = 0 last_yes_file = None """Read last pickle file or run vasp """ if last_yes_file: cl = CalculationVasp().deserialize(last_yes_file) printlog('Successfully deserialized') xcart_voids = cl.end.get_specific_elements([300], fmt = 'x') # extract voids form the last calculation else: cl = vasp_run(3, 'first run', vasprun_command = vasprun_command) if xcart_voids: # read void coordinates cl.end = cl.end.add_atoms(xcart_voids, 'void') printlog('I found', len(xcart_voids), 'voids in config file. Added to structure.') if check(cl) == 0: cl.serialize('0-yes') copyfile('OUTCAR', 'OUTCAR-0') copyfile('OSZICAR', 'OSZICAR-0') copyfile('CONTCAR', 'CONTCAR-0') copyfile('OUTCAR', 'OUTCAR_last') copyfile('CONTCAR', 'CONTCAR_last') with open('ENERGIES', 'w') as f: f.write('{:5d} {:.5f}\n'.format(0, cl.e0)) else: printlog('Calculation is broken, no data was saved, exiting ...', imp = 'y') sys.exit() if debug2: sys.exit() return cl, last_number
last_yes_file = None """Read last pickle file or run vasp """ if last_yes_file: cl = CalculationVasp().deserialize(last_yes_file) printlog('Successfully deserialized') if 0: #to correct mistake on first step and add void to pickle if 'xvoid' in params and len( params['xvoid']) > 0: # read void coordinates cl.end = cl.end.add_atoms(params['xvoid'], 'void') printlog('I found', len(params['xvoid']), 'voids in config file. Added to structure.') cl.serialize('0-yes') else: cl = vasp_run(3, 'first run') if 'xvoid' in params and len( params['xvoid']) > 0: # read void coordinates cl.end = cl.end.add_atoms(params['xvoid'], 'void') printlog('I found', len(params['xvoid']), 'voids in config file. Added to structure.') cl.serialize('0-yes') copyfile('OSZICAR', 'OSZICAR-0') copyfile('CONTCAR', 'CONTCAR-0') with open('ENERGIES', 'w') as f: f.write('{:5d} {:.5f}\n'.format(0, cl.e0))
printlog('Energies before and after are {:3.3f} and {:3.3f}, dE = {:3.3f}'.format(E1, E2, E2 - E1), imp = 'y') with open('ENERGIES', 'a') as f: f.write('{:5d} {:.5f}\n'.format(i_mcstep, cl_new.e0)) if metropolis(E1, E2, temperature): cl = cl_new if xcart_voids: #insert voids cl_new.end = cl_new.end.add_atoms(xcart_voids, 'void') # here voids are inserted back if not debug: cl.serialize(str(i_mcstep)+'-yes') copyfile('CONTCAR', 'CONTCAR_last') copyfile('OUTCAR', 'OUTCAR_last') if os.path.exists('LOCPOT'): copyfile('LOCPOT', 'LOCPOT_last') st = cl_new.end printlog('The step was accepted', imp = 'y') else: printlog('The step was rejected', imp = 'y') if not debug: cl_new.serialize(str(i_mcstep)+'-no')