Skip to content

Commit

Permalink
nwchem tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Zarko Ivkovic committed Jun 10, 2023
1 parent 4eb2d39 commit 8dd25e0
Show file tree
Hide file tree
Showing 5 changed files with 1,518 additions and 71 deletions.
17 changes: 17 additions & 0 deletions ccinput/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
InternalError,
ImpossibleCalculation,
MissingParameter,
UnimplementedError,
)
from ccinput.utilities import (
get_abs_software,
Expand Down Expand Up @@ -446,7 +447,23 @@ def to_xtb(self):
t = "dihedral"

return f"{t}: {ids_str}\n"

def to_nwchem(self):
ids_str = " ".join([str(i) for i in self.ids])
type = len(self.ids)
if type == 1:
t = "fix atom"
elif type == 2:
t = "spring bond"
elif type == 3:
raise UnimplementedError("Constraints on angles are not implemented in nwchem")
elif type == 4:
t = "spring dihedral"

if self.scan:
pass # TO DO
else:
return f"{t} {ids_str} \n"

def parse_freeze_constraints(arr, xyz_str, software=""):
if len(arr) == 0:
Expand Down
4 changes: 2 additions & 2 deletions ccinput/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ class CalcType(Enum):
"lpnoccsd": [],
"lpnoccsdt": [],
"lpnoqcisd": [],
"lpnoqcisdt": [],
"l7pnoqcisdt": [],
"dlpnoccsd": [],
"dlpnoccsdt": [],
"dlpnoqcisd": [],
Expand Down Expand Up @@ -1698,7 +1698,7 @@ class CalcType(Enum):
"revpbe": "revpbe",
"rpbe": "rpbe",
},
"nwchem": { # Values are correct, keys need to be checked! - Zarko
"nwchem": {
"hf": "hf",
"rohf": "rohf",
"uhf": "uhf",
Expand Down
128 changes: 59 additions & 69 deletions ccinput/packages/nwchem.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class NWChemCalculation:

KEYWORDS = {
CalcType.OPT: ["optimize"],
# CalcType.CONSTR_OPT: ["opt"],
CalcType.CONSTR_OPT: ["optimize"],
CalcType.TS: ["saddle"],
CalcType.FREQ: ["freq"],
CalcType.NMR: ["property"],
Expand All @@ -61,44 +61,7 @@ class NWChemCalculation:
# CalcType.UVVIS_TDA: ["tda"],
CalcType.OPTFREQ: ["optimize", "freq"],
}
BLOCK_KEYWORDS = {
"method" : [
"sym",
"adapt",
"tol2e",
"vectors",
"tresh",
"maxiter",
"profile",
"diis",
"direct",
"semidirect",
"nr",
"level",
"convergence",
"grid",
"tolerances",
"decomp",
"odft",
"incore",
"iterations",
"max_ovl",
"cgmin",
"rodft",
"disp",
"xdm",
"noio",
"print",
"noprint",
"fon",
"nodisk",
"fukui",
"noscf",
],
"calculation" : [
"a", # TO DO
],
}

BLOCK_NAMES = {
CalcType.OPT : "driver",
CalcType.NMR : "property",
Expand All @@ -108,12 +71,12 @@ class NWChemCalculation:
}
def __init__(self, calc):
self.calc = calc
if self.calc.parameters.theory_level == 'hf' : # Name of the block for HF is scf
self.calc.parameters.theory_level = 'scf'
self.calc.mem = f"{self.calc.mem} mb"
self.has_scan = False
self.appendix = []
self.command_line = ""
if self.calc.parameters.theory_level == 'hf' or self.calc.parameters.method == 'uhf' or self.calc.parameters.method == 'rhf' : # Name of the block for HF is scf
self.calc.parameters.theory_level = 'scf'
self.method_block=f"{self.calc.parameters.theory_level}"
self.calculation_block=""
self.additional_block=""
Expand Down Expand Up @@ -143,18 +106,23 @@ def clean(self, s):

def separate_lines(self,text):
lines = text.split(';')
clean = []
for line in lines :
line = self.clean(line)
return "\n".join(lines)
if line != '':
clean.append(self.clean(line.lower()).strip())
else :
pass
return "\n".join(clean)

def handle_tasks(self):
for word in self.KEYWORDS[self.calc.type]:
self.tasks += f'task {self.calc.parameters.theory_level} {word} \n'
#handle levels of theory
if(self.calc.parameters.method == 'hf' or self.calc.parameters.method in SYN_METHODS['hf']) :
scf_block = f"""
{SOFTWARE_MULTIPLICITY['nwchem'][self.calc.multiplicity]}
"""
if(self.calc.parameters.theory_level == 'scf') :
scf_block = "\n"
if self.calc.parameters.method != 'hf':
scf_block += f"{self.calc.parameters.method} \n"
scf_block += f"{SOFTWARE_MULTIPLICITY['nwchem'][self.calc.multiplicity]} \n"
self.method_block+= scf_block
if(self.calc.parameters.theory_level == 'dft') :
dft_block = f"""
Expand All @@ -166,33 +134,54 @@ def handle_tasks(self):
self.method_block += "disp vdw 3 \n"
elif self.calc.parameters.d3bj :
self.method_block += "disp vdw 4 \n"
if self.calc.type == CalcType.NMR:
self.calculation_block += f" \n property \n shielding \n"

def handle_basis_sets(self):
basis_set = get_basis_set(self.calc.parameters.basis_set, "nwchem")
if(basis_set != ''):
self.basis_set = f"* library {basis_set}"
def handle_specifications(self):
if self.calc.parameters.specifications != '':
s = self.separate_lines(self.calc.parameters.specifications)
for spec in s.split('\n'):
matched = re.search(r".*\((.*)\)",spec)
if matched == None :
self.additional_block += f"{spec} \n"
else :
command = matched.group(1)
block_name = spec[:matched.span(1)[0]-1]
if block_name == 'scf' :
self.method_block += f"{command} \n"
elif block_name == 'opt' or block_name == 'ts' :
if self.calculation_block == '':
self.calculation_block += f"\n driver \n"
self.calculation_block += f"{command} \n"
elif block_name == 'nmr' :
if self.calculation_block == '':
self.calculation_block += f" \n property \n"
self.calculation_block += f"{command} \n"
if self.additional_block != '':
self.additional_block = '\n' + self.additional_block
if self.calc.parameters.specifications != '':
temp = "\n" # Here we will store frequency related specifiations in case of FREQOPT calculations
s = self.separate_lines(self.calc.parameters.specifications)
for spec in s.split('\n'):
matched = re.search(r".*\((.*)\)",spec)
if matched == None :
self.additional_block += f"{spec} \n"
else :
command = matched.group(1)
block_name = spec[:matched.span(1)[0]-1]
if block_name == 'scf' :
self.method_block += f"{command} \n"
elif (block_name == 'opt' or block_name == 'ts') and (self.calc.type == CalcType.CONSTR_OPT or self.calc.type == CalcType.OPT or self.calc.type == CalcType.TS or self.calc.type == CalcType.OPTFREQ) :
if self.calculation_block == '':
self.calculation_block += f"\n driver \n"
self.calculation_block += f"{command} \n"
elif block_name == 'nmr' and self.calc.type == CalcType.NMR :
self.calculation_block += f"{command} \n"
elif block_name == 'freq' and self.calc.type == CalcType.FREQ :
if self.calculation_block == '':
self.calculation_block += f"\n freq \n"
self.calculation_block += f"{command} \n"
elif block_name == 'freq' and self.calc.type == CalcType.OPTFREQ :
temp += f"{command} \n"
if temp != '\n':
self.additional_block += f'freq {temp} end \n'

# Handle contraints
if self.calc.type == CalcType.CONSTR_OPT:
if len(self.calc.constraints) == 0:
raise InvalidParameter("No constraint in constrained optimisation mode")
self.additional_block += "constraints \n"
for constraint in self.calc.constraints:
self.additional_block += constraint.to_nwchem()
self.additional_block += "end \n"

if self.additional_block.strip() != '':
self.additional_block = '\n' + self.additional_block



def handle_xyz(self):
lines = [i + "\n" for i in clean_xyz(self.calc.xyz).split("\n") if i != ""]
Expand All @@ -206,7 +195,8 @@ def close_blocks(self):
self.method_block += " end \n"
if self.calculation_block != '':
self.calculation_block += " end \n"

def to_lowercase(self,text):
text.lower()
def create_input_file(self):
raw = self.TEMPLATE.format(
self.calc.header,
Expand Down
Loading

0 comments on commit 8dd25e0

Please sign in to comment.