Coverage for gpaw/cli/run.py: 53%
36 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-09 00:21 +0000
1from ase.cli.run import Runner, str2dict, CLICommand as ASECLICommand
3from gpaw import GPAW
4from gpaw.mixer import Mixer, MixerSum
5from gpaw.occupations import (FermiDirac, MethfesselPaxton,
6 MarzariVanderbilt)
7from gpaw import PW
10class GPAWRunner(Runner):
11 def __init__(self):
12 Runner.__init__(self)
13 self.calculator_name = 'gpaw'
15 def parse(self, args):
16 args.calculator = 'gpaw'
17 return Runner.parse(self, args)
19 def set_calculator(self, atoms, name):
20 parameter_namespace = {
21 'PW': PW,
22 'FermiDirac': FermiDirac,
23 'MethfesselPaxton': MethfesselPaxton,
24 'MarzariVanderbilt': MarzariVanderbilt,
25 'Mixer': Mixer,
26 'MixerSum': MixerSum}
27 parameters = str2dict(self.args.parameters, parameter_namespace)
28 txt = parameters.pop('txt', self.get_filename(name, 'txt'))
29 atoms.calc = GPAW(txt=txt, **parameters)
31 def calculate(self, atoms, name):
32 data = Runner.calculate(self, atoms, name)
33 if self.args.write:
34 atoms.calc.write(self.args.write)
35 if self.args.write_all:
36 atoms.calc.write(self.args.write_all, 'all')
37 return data
40class CLICommand:
41 """Run calculation with GPAW.
43 Four types of calculations can be done:
45 * single point
46 * atomic relaxations
47 * unit cell + atomic relaxations
48 * equation-of-state
50 Examples of the four types of calculations:
52 gpaw run -p xc=PBE h2o.xyz
53 gpaw run -p xc=PBE h2o.xyz -f 0.01
54 gpaw run -p "xc=PBE,kpts={density:4}" cu.traj -s 0.01
55 gpaw run -p "xc=PBE,kpts={density:4}" cu.traj -E 5,2.0
56 """
58 @staticmethod
59 def add_arguments(parser):
60 ASECLICommand.add_more_arguments(parser)
61 parser.add_argument('--dry-run', type=int, default=0,
62 metavar='NCPUS',
63 help='Dry run on NCPUS cpus.')
64 parser.add_argument('-w', '--write', help='Write gpw-file.')
65 parser.add_argument('-W', '--write-all',
66 help='Write gpw-file with wave functions.')
68 @staticmethod
69 def run(args):
70 runner = GPAWRunner()
71 runner.parse(args)
72 runner.run()