Skip to content

Commit

Permalink
Merge pull request #4787 from jtkrogel/nx_spinor_workflow
Browse files Browse the repository at this point in the history
Nexus: enable driving spinor workflows
  • Loading branch information
ye-luo committed Dec 5, 2023
2 parents bd31b9b + e870f7f commit 247067f
Show file tree
Hide file tree
Showing 4 changed files with 438 additions and 166 deletions.
1 change: 1 addition & 0 deletions nexus/lib/nexus.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@

from qmcpack_converters import Pw2qmcpack , Pw2qmcpackInput , Pw2qmcpackAnalyzer , generate_pw2qmcpack_input , generate_pw2qmcpack
from qmcpack_converters import Convert4qmc, Convert4qmcInput, Convert4qmcAnalyzer, generate_convert4qmc_input, generate_convert4qmc
from qmcpack_converters import Convertpw4qmc, Convertpw4qmcInput, Convertpw4qmcAnalyzer, generate_convertpw4qmc_input, generate_convertpw4qmc
from qmcpack_converters import PyscfToAfqmc, PyscfToAfqmcInput, PyscfToAfqmcAnalyzer, generate_pyscf_to_afqmc_input, generate_pyscf_to_afqmc

from pwscf_postprocessors import PP , PPInput , PPAnalyzer , generate_pp_input , generate_pp
Expand Down
16 changes: 14 additions & 2 deletions nexus/lib/qmcpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from qmcpack_input import generate_opt,generate_opts
from qmcpack_input import check_excitation_type
from qmcpack_analyzer import QmcpackAnalyzer
from qmcpack_converters import Pw2qmcpack,Convert4qmc,PyscfToAfqmc
from qmcpack_converters import Pw2qmcpack,Convert4qmc,Convertpw4qmc,PyscfToAfqmc
from debug import ci,ls,gs
from developer import unavailable
from nexus_base import nexus_core
Expand Down Expand Up @@ -174,7 +174,7 @@ def incorporate_result(self,result_name,result,sim):
input = self.input
system = self.system
if result_name=='orbitals':
if isinstance(sim,Pw2qmcpack):
if isinstance(sim,Pw2qmcpack) or isinstance(sim,Convertpw4qmc):

h5file = result.h5file

Expand Down Expand Up @@ -283,6 +283,18 @@ def incorporate_result(self,result_name,result,sim):
opt = QmcpackInput(opt_file)
wavefunction = input.get('wavefunction')
optwf = opt.qmcsystem.wavefunction
# handle spinor case
spinor = input.get('spinor')
if spinor is not None and spinor:
# remove u-d term from optmized jastrow
J2 = optwf.get('J2')
if J2 is not None:
corr = J2.get('correlation')
if 'ud' in corr:
del corr.ud
#end if
#end if
#end if
def process_jastrow(wf):
if 'jastrow' in wf:
js = [wf.jastrow]
Expand Down
165 changes: 164 additions & 1 deletion nexus/lib/qmcpack_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,6 @@ def __init__(self,*args,**kwargs):
self.input_code = None
#end def __init__


def set_app_name(self,app_name):
self.app_name = app_name
self.input.set_app_name(app_name)
Expand Down Expand Up @@ -927,6 +926,170 @@ def generate_convert4qmc(**kwargs):



class Convertpw4qmcInput(SimulationInput):
def __init__(self,data_file=None):
self.data_file=data_file
#end def __init__

def read(self, filepath):
None
#end def read

def write(self, filepath):
None

#end class Convertpw4qmcInput

def generate_convertpw4qmc_input(**kwargs):
return Convertpw4qmcInput(**kwargs)
#end def genreate_convertpw4qmc_input

class Convertpw4qmcAnalyzer(SimulationAnalyzer):
def __init__(self,arg0):
if isinstance(arg0,Simulation):
self.infile = arg0.infile
else:
self.infile = arg0
#end if
#end def __init__

def analyze(self):
None
#end def analyze
#end class Convertpw4qmcAnalyzer


class Convertpw4qmc(Simulation):
input_type = Convertpw4qmcInput
analyzer_type = Convertpw4qmcAnalyzer
generic_identifier = 'convertpw4qmc'
application = 'convertpw4qmc'
application_properties = set(['serial'])
application_results = set(['orbitals'])
renew_app_command = True

def set_app_name(self,app_name):
self.app_name = app_name
#end def set_app_name

def propagate_identifier(self):
None
#end def propagate_identifier

def set_files(self):
# no input file
self.infile = None
if self.outfile is None:
self.outfile = self.identifier + self.outfile_extension
#end if
if self.errfile is None:
self.errfile = self.identifier + self.errfile_extension
#end if
#end def set_files

def check_result(self,result_name,sim):
return result_name=='orbitals'
#end def check_result

def get_result(self,result_name,sim):
result = obj()
input = self.input
if result_name=='orbitals':
wfn_file = 'eshdf.h5'
orbfile = os.path.join(self.locdir,wfn_file)
result.location = orbfile
result.h5file = orbfile
else:
self.error('ability to get result '+result_name+' has not been implemented')
#end if
return result
#end def get_result

def get_output_files(self):
output_files = []
return output_files
#end def get_output_files

def app_command(self):
app_name = self.app_name
data_file = self.input.data_file
command = '{} {}'.format(app_name,data_file)
return command
#end def app_command

def incorporate_result(self,result_name,result,sim):
implemented = True
if result_name=='orbitals':
if isinstance(sim,Pwscf):
pwin = sim.input.control
pwprefix = 'pwscf'
p2prefix = 'pwscf'
pwoutdir = './'
p2outdir = './'
if 'prefix' in pwin:
pwprefix = pwin.prefix
#end if
if 'outdir' in pwin:
pwoutdir = pwin.outdir
#end if
if pwoutdir.startswith('./'):
pwoutdir = pwoutdir[2:]
#end if
pwsdir = os.path.abspath(os.path.join(sim.locdir ,pwoutdir, pwprefix+'.save'))
charge_density_h5 = os.path.join(pwsdir, 'charge-density.hdf5')
data_file_schema = os.path.join(pwsdir, 'data-file-schema.xml')
errors = False
if not os.path.exists(data_file_schema):
self.error('to use orbitals, '+self.generic_identifier+' must have data-file-schema.xml file', exit=False)
errors = True
#end if
if not os.path.exists(charge_density_h5):
self.error('to use orbitals, '+self.generic_identifier+' must have charge-density.h5 file.\nNeed to rebuild QE with hdf5 support', exit=False)
errors = True
#end if
if errors:
self.error(self.generic_identifier+' cannot use orbitals from pwscf')
#end if
if self.input.data_file is None:
self.input.data_file = data_file_schema
else:
implemented = False
#end if
else:
implemented = False
#end if
if not implemented:
self.error('ability to incorporate result "{0}" from {1} has not been implemented'.format(result_name,sim.__class__.__name__))
#end if
#end def incorporate_result

def check_sim_status(self):
h5file = os.path.join(self.locdir,'eshdf.h5')
must_exist = [h5file]

files_exist = True
for file in must_exist:
files_exist = files_exist and os.path.exists(file)
#end for
success = files_exist

self.finished = files_exist and self.job.finished
#end def check_sim_status
#end class Convertpw4qmc



def generate_convertpw4qmc(**kwargs):
sim_args,inp_args = Simulation.separate_inputs(kwargs)

if not 'input' in sim_args:
sim_args.input = generate_convertpw4qmc_input(**inp_args)
#end if
sim = Convertpw4qmc(**sim_args)

return sim
#end def generate_convertpw4qmc



class PyscfToAfqmcInput(SimulationInput):
Expand Down

0 comments on commit 247067f

Please sign in to comment.