def prepare_folder(self, entry_id, workdir='.', source_dir='.'): """ Prepare directories for abinit execution :param entry_id: bson.ObjectID of the entry that will be used for preparing the folder :param source_dir: (str) is the directory where 'abinit.files' and 'batch.pbs' should be present those directories will be symbolically linked inside the individual work directories :param workdir: (str) Base work directory for abinit executions. Inside this directory, a set of subdirectories will be created using the mongo ID as name. """ # Individual workdir iworkdir = workdir + os.sep + str(entry_id) if not os.path.isdir(iworkdir): os.mkdir(iworkdir) if os.path.lexists(iworkdir + os.sep + 'abinit.files'): os.remove(iworkdir + os.sep + 'abinit.files') if not os.path.isfile(source_dir + os.sep + 'abinit.files'): print( 'WARNIG: The file %s should be present on %s, symbolic links will be created pointing ' 'to that location' % ('abinit.files', source_dir)) os.symlink(os.path.abspath(source_dir + os.sep + 'abinit.files'), iworkdir + os.sep + 'abinit.files') abiinput = AbinitInput(self.input_path) params = self.get_correlation_params(entry_id, final=False) dmatpawu = params2dmatpawu(params) abiinput['dmatpawu'] = list(dmatpawu.flatten()) abiinput.write(iworkdir + os.sep + 'abinit.in') d_abiinput = AbinitInput(iworkdir + os.sep + 'abinit.in') d_dmatpawu = d_abiinput['dmatpawu'] assert (d_dmatpawu is not None) d_params = dmatpawu2params(d_dmatpawu, self.ndim) if not np.all( np.sum(d_params['occupations'], axis=1) == np.array( self.num_electrons_dftu)): print( 'ERROR: Inconsistent number of DFT+U electrons for correlated orbitals: %s' % entry_id) print('From the population: %s ' % self.num_electrons_dftu) print('From "abinit.in": %s ' % d_params['occupations'])
def prepare_folder(self, entry_id, workdir='.', source_dir='.'): """ Prepare directories for abinit execution :param entry_id: bson.ObjectID of the entry that will be used for preparing the folder :param source_dir: (str) is the directory where 'abinit.files' and 'batch.pbs' should be present those directories will be symbolically linked inside the individual work directories :param workdir: (str) Base work directory for abinit executions. Inside this directory, a set of subdirectories will be created using the mongo ID as name. """ # Individual workdir iworkdir = workdir+os.sep+str(entry_id) if not os.path.isdir(iworkdir): os.mkdir(iworkdir) if os.path.lexists(iworkdir + os.sep + 'abinit.files'): os.remove(iworkdir + os.sep + 'abinit.files') if not os.path.isfile(source_dir + os.sep + 'abinit.files'): print('WARNIG: The file %s should be present on %s, symbolic links will be created pointing ' 'to that location' % ('abinit.files', source_dir)) os.symlink(os.path.abspath(source_dir + os.sep + 'abinit.files'), iworkdir + os.sep + 'abinit.files') abiinput = AbinitInput(self.input_path) params = self.get_correlation_params(entry_id, final=False) dmatpawu = params2dmatpawu(params) abiinput['dmatpawu'] = list(dmatpawu.flatten()) abiinput.write(iworkdir + os.sep + 'abinit.in') d_abiinput = AbinitInput(iworkdir + os.sep + 'abinit.in') d_dmatpawu = d_abiinput['dmatpawu'] assert(d_dmatpawu is not None) d_params = dmatpawu2params(d_dmatpawu, self.ndim) if not np.all(np.sum(d_params['occupations'], axis=1) == np.array(self.num_electrons_dftu)): print('ERROR: Inconsistent number of DFT+U electrons for correlated orbitals: %s' % entry_id) print('From the population: %s ' % self.num_electrons_dftu) print('From "abinit.in": %s ' % d_params['occupations'])
print('Yes') print("Checking that abinit.in contains value for lpawu...", end='') if 'lpawu' not in abi.variables: print('No') raise ValueError("ERROR: Could not open abinit.in") else: print('Yes, max lpawu=%d' % max(abi['lpawu'])) print('Setting ABINIT variables usedmatpu=%d, nstep=%d and tolvrs=%e' % (usedmatpu, nstep, tolvrs)) abi['usedmatpu'] = usedmatpu abi['nstep'] = nstep abi['tolvrs'] = tolvrs print('Writting modified abinit.in') abi.write('abinit.in') # Getting the index from the last execution and adding one for the next run index = 0 while True: if os.path.isfile('abinit_%02d.in' % index): index += 1 else: break if index >= max_nruns: print( "Total number of runs has been achieve already, increse 'max_nruns' if you want to continue" ) parser.print_help() exit(1)
if not os.path.isdir(args.basepath + os.sep + name): os.mkdir(args.basepath + os.sep + name) abi = AbinitInput(args.basepath + os.sep + 'abinit.in') abi['upawu'] = "" for i in dbi['u']: abi['upawu'] += str(i) + " " abi['upawu'] += 'eV' abi['jpawu'] = "" for i in dbi['j']: abi['jpawu'] += str(i) + " " abi['jpawu'] += 'eV' abipath = args.basepath + os.sep + name + os.sep + 'abinit.in' abi.write(abipath) abifiles = args.basepath + os.sep + name + os.sep + 'abinit.files' if os.path.lexists(abifiles): os.remove(abifiles) os.symlink( os.path.abspath(args.basepath + os.sep + 'abinit.files'), abifiles) for i in [x for x in os.listdir(args.basepath) if x[-3:] == 'xml']: psp = args.basepath + os.sep + name + os.sep + i if os.path.lexists(psp): os.remove(psp) os.symlink(os.path.abspath(args.basepath + os.sep + i), psp) popu[name] = OrbitalDFTU(pcdb, abipath)
if not os.path.isdir(args.basepath + os.sep + name): os.mkdir(args.basepath + os.sep + name) abi = AbinitInput(args.basepath + os.sep + 'abinit.in') abi['upawu'] = "" for i in dbi['u']: abi['upawu'] += str(i) + " " abi['upawu'] += 'eV' abi['jpawu'] = "" for i in dbi['j']: abi['jpawu'] += str(i) + " " abi['jpawu'] += 'eV' abipath = args.basepath + os.sep + name + os.sep + 'abinit.in' abi.write(abipath) abifiles = args.basepath + os.sep + name + os.sep + 'abinit.files' if os.path.lexists(abifiles): os.remove(abifiles) os.symlink(os.path.abspath(args.basepath + os.sep + 'abinit.files'), abifiles) for i in [x for x in os.listdir(args.basepath) if x[-3:] == 'xml']: psp = args.basepath + os.sep + name + os.sep + i if os.path.lexists(psp): os.remove(psp) os.symlink(os.path.abspath(args.basepath + os.sep + i), psp) popu[name] = OrbitalDFTU(pcdb, abipath) # Specific actions for 'populate', 'run', 'search' and 'plot' if args.subparser_name == 'populate':