Coverage for ase/calculators/gamess_us.py: 66.67%
30 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
1import warnings
3from ase.calculators.calculator import FileIOCalculator
4from ase.io import read, write
5from ase.io.gamess_us import clean_userscr, get_userscr
8class GAMESSUS(FileIOCalculator):
9 implemented_properties = ['energy', 'forces', 'dipole']
10 _legacy_default_command = 'rungms PREFIX.inp > PREFIX.log 2> PREFIX.err'
11 discard_results_on_any_change = True
13 def __init__(
14 self,
15 restart=None,
16 ignore_bad_restart_file=FileIOCalculator._deprecated,
17 label='gamess_us',
18 atoms=None,
19 command=None,
20 userscr=None,
21 **kwargs,
22 ):
23 """
24 GAMESS-US keywords are specified using dictionaries of keywords.
25 For example, to run a CCSD(T)/cc-pVDZ calculation, you might use the
26 following arguments:
28 >>> calc = GAMESSUS(contrl={'scftyp': 'rhf', 'cctyp': 'ccsd(t)',
29 >>> 'ispher': 1, 'runtyp': 'energy'},
30 >>> basis={'gbasis': 'CCD'})
32 This will create an input file that looks like the following:
34 >>> $CONTRL
35 >>> SCFTYP=RHF
36 >>> CCTYP=CCSD(T)
37 >>> ISPHER=1
38 >>> RUNTYP=ENERGY
39 >>> $END
40 >>>
41 >>> $BASIS
42 >>> GBASIS=CCSD
43 >>> $END
45 See the INPUT.DOC file provided by GAMESS-US for more information.
47 If `runtyp` is not specified, it will be set automatically.
49 If no basis is specified, 3-21G will be used by default.
50 A dictionary containing literal per-index or per-element basis sets
51 can be passed to the `basis` keyword. This will result in the basis
52 set being printed in the $DATA block, alongside the geometry
53 specification.
54 Otherwise, `basis` is assumed to contain keywords for the $BASIS
55 block, such as GBASIS and NGAUSS.
57 If a multiplicity is not set in contrl['mult'], the multiplicity
58 will be guessed based on the Atoms object's initial magnetic moments.
60 The GAMESSUS calculator has some special keyword:
62 xc: str
63 The exchange-correlation functional to use for DFT calculations.
64 In most circumstances, setting xc is equivalent to setting
65 contrl['dfttyp']. xc will be ignored if a value has also
66 been provided to contrl['dfttyp'].
68 userscr: str
69 The location of the USERSCR directory specified in your
70 `rungms` script. If not provided, an attempt will be made
71 to automatically determine the location of this directory.
72 If this fails, you will need to manually specify the path
73 to this directory to the calculator using this keyword.
75 ecp: dict
76 A per-index or per-element dictionary of ECP specifications.
77 """
79 # Backward compatibility fix:
80 if command is None and 'ASE_GAMESSUS_COMMAND' in self.cfg:
81 command = self.cfg['ASE_GAMESSUS_COMMAND']
83 FileIOCalculator.__init__(
84 self,
85 restart,
86 ignore_bad_restart_file,
87 label,
88 atoms,
89 command,
90 **kwargs,
91 )
92 self.userscr = userscr
94 def _get_name(self):
95 return 'gamess_us'
97 def calculate(self, *args, **kwargs):
98 if self.userscr is None:
99 if 'rungms' in self.command:
100 self.userscr = get_userscr(self.prefix, self.command)
102 if self.userscr is None:
103 warnings.warn(
104 'Could not determine USERSCR! '
105 'GAMESS may refuse to run more than once for '
106 'this job. Please pass userscr to the GAMESSUS '
107 'Calculator if you run into problems!'
108 )
109 else:
110 clean_userscr(self.userscr, self.prefix)
112 FileIOCalculator.calculate(self, *args, **kwargs)
114 def write_input(self, atoms, properties=None, system_changes=None):
115 FileIOCalculator.write_input(self, atoms, properties, system_changes)
116 write(
117 self.label + '.inp',
118 atoms,
119 properties=properties,
120 format='gamess-us-in',
121 **self.parameters,
122 )
124 def read_results(self):
125 output = read(self.label + '.log')
126 self.calc = output.calc
127 self.results = output.calc.results