Coverage for /builds/kinetik161/ase/ase/calculators/gamess_us.py: 61.54%

26 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-12-10 11:04 +0000

1import warnings 

2 

3from ase.calculators.calculator import FileIOCalculator 

4from ase.io import read, write 

5from ase.io.gamess_us import clean_userscr, get_userscr 

6 

7 

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 

12 

13 def __init__(self, restart=None, 

14 ignore_bad_restart_file=FileIOCalculator._deprecated, 

15 label='gamess_us', atoms=None, command=None, userscr=None, 

16 **kwargs): 

17 """ 

18 GAMESS-US keywords are specified using dictionaries of keywords. 

19 For example, to run a CCSD(T)/cc-pVDZ calculation, you might use the 

20 following arguments: 

21 

22 >>> calc = GAMESSUS(contrl={'scftyp': 'rhf', 'cctyp': 'ccsd(t)', 

23 >>> 'ispher': 1, 'runtyp': 'energy'}, 

24 >>> basis={'gbasis': 'CCD'}) 

25 

26 This will create an input file that looks like the following: 

27 

28 >>> $CONTRL 

29 >>> SCFTYP=RHF 

30 >>> CCTYP=CCSD(T) 

31 >>> ISPHER=1 

32 >>> RUNTYP=ENERGY 

33 >>> $END 

34 >>> 

35 >>> $BASIS 

36 >>> GBASIS=CCSD 

37 >>> $END 

38 

39 See the INPUT.DOC file provided by GAMESS-US for more information. 

40 

41 If `runtyp` is not specified, it will be set automatically. 

42 

43 If no basis is specified, 3-21G will be used by default. 

44 A dictionary containing literal per-index or per-element basis sets 

45 can be passed to the `basis` keyword. This will result in the basis 

46 set being printed in the $DATA block, alongside the geometry 

47 specification. 

48 Otherwise, `basis` is assumed to contain keywords for the $BASIS 

49 block, such as GBASIS and NGAUSS. 

50 

51 If a multiplicity is not set in contrl['mult'], the multiplicity 

52 will be guessed based on the Atoms object's initial magnetic moments. 

53 

54 The GAMESSUS calculator has some special keyword: 

55 

56 xc: str 

57 The exchange-correlation functional to use for DFT calculations. 

58 In most circumstances, setting xc is equivalent to setting 

59 contrl['dfttyp']. xc will be ignored if a value has also 

60 been provided to contrl['dfttyp']. 

61 

62 userscr: str 

63 The location of the USERSCR directory specified in your 

64 `rungms` script. If not provided, an attempt will be made 

65 to automatically determine the location of this directory. 

66 If this fails, you will need to manually specify the path 

67 to this directory to the calculator using this keyword. 

68 

69 ecp: dict 

70 A per-index or per-element dictionary of ECP specifications. 

71 """ 

72 FileIOCalculator.__init__(self, restart, ignore_bad_restart_file, 

73 label, atoms, command, **kwargs) 

74 self.userscr = userscr 

75 

76 def calculate(self, *args, **kwargs): 

77 if self.userscr is None: 

78 if 'rungms' in self.command: 

79 self.userscr = get_userscr(self.prefix, self.command) 

80 

81 if self.userscr is None: 

82 warnings.warn("Could not determine USERSCR! " 

83 "GAMESS may refuse to run more than once for " 

84 "this job. Please pass userscr to the GAMESSUS " 

85 "Calculator if you run into problems!") 

86 else: 

87 clean_userscr(self.userscr, self.prefix) 

88 

89 FileIOCalculator.calculate(self, *args, **kwargs) 

90 

91 def write_input(self, atoms, properties=None, system_changes=None): 

92 FileIOCalculator.write_input(self, atoms, properties, system_changes) 

93 write(self.label + '.inp', atoms, properties=properties, 

94 format='gamess-us-in', **self.parameters) 

95 

96 def read_results(self): 

97 output = read(self.label + '.log') 

98 self.calc = output.calc 

99 self.results = output.calc.results