1
2import numpy as np
3
4from generic import obj
5from developer import DevBase,error
6from unit_converter import convert
7from pseudopotential import pp_elem_label
8from structure import generate_structure
9from simulation import SimulationInput
10
11
12class RmgInputSettings(DevBase):
13    enforce_min_value = True
14    enforce_max_value = True
15    enforce_allowed   = True
16    check_on_write    = True
17#end class RmgInputSettings
18
19
20# raw input spec below
21#   taken directly from
22#     https://github.com/RMGDFT/rmgdft/wiki/Input-File-Options
23#   changes made from website values
24#     write_data_period
25#       Max value: 50     -> 500
26#     pseudopotential
27#       Key type : string -> formatted
28#     Hubbard_U
29#       Key type : string -> formatted
30
31raw_input_spec = '''
32Control options
33
34    Key name:     a_length
35    Required:     no
36    Key type:     double
37    Expert:       No
38    Experimental: No
39    Min value:    0.000000e+00
40    Max value:    unlimited
41    Default:      0.000000e+00
42    Description:  First lattice constant.
43
44    Key name:     b_length
45    Required:     no
46    Key type:     double
47    Expert:       No
48    Experimental: No
49    Min value:    0.000000e+00
50    Max value:    unlimited
51    Default:      0.000000e+00
52    Description:  Second lattice constant.
53
54    Key name:     c_length
55    Required:     no
56    Key type:     double
57    Expert:       No
58    Experimental: No
59    Min value:    0.000000e+00
60    Max value:    unlimited
61    Default:      0.000000e+00
62    Description:  Third lattice constant.
63
64    Key name:     calculation_mode
65    Required:     no
66    Key type:     string
67    Expert:       No
68    Experimental: No
69    Default:      "Quench Electrons"
70    Allowed:      "Exx Only" "NEB Relax" "Band Structure Only" "Psi Plot" "Plot"
71                  "Constant Pressure And Energy" "TDDFT" "Dimer Relax" "Constant
72                  Temperature And Energy" "Constant Volume And Energy" "Relax
73                  Structure" "Quench Electrons"
74    Description:  Type of calculation to perform.
75
76    Key name:     cell_relax
77    Required:     no
78    Key type:     boolean
79    Expert:       No
80    Experimental: No
81    Default:      "false"
82    Description:  flag to control unit cell relaxation
83
84    Key name:     coalesce_factor
85    Required:     no
86    Key type:     integer
87    Expert:       Yes
88    Experimental: No
89    Min value:    1
90    Max value:    16
91    Default:      4
92    Description:  Grid coalescing factor.
93
94    Key name:     coalesce_states
95    Required:     no
96    Key type:     boolean
97    Expert:       Yes
98    Experimental: No
99    Default:      "false"
100    Description:  Flag indicating whether or not to coalesce states.
101
102    Key name:     compressed_infile
103    Required:     no
104    Key type:     boolean
105    Expert:       No
106    Experimental: No
107    Default:      "true"
108    Description:  Flag indicating whether or not parallel restart wavefunction file
109                  uses compressed format.
110
111    Key name:     compressed_outfile
112    Required:     no
113    Key type:     boolean
114    Expert:       No
115    Experimental: No
116    Default:      "true"
117    Description:  Flag indicating whether or not parallel output wavefunction file
118                  uses compressed format.
119
120    Key name:     description
121    Required:     no
122    Key type:     string
123    Expert:       No
124    Experimental: No
125    Default:      ""
126    Allowed:
127    Description:  Description of the run.
128
129    Key name:     energy_convergence_criterion
130    Required:     no
131    Key type:     double
132    Expert:       No
133    Experimental: No
134    Min value:    1.000000e-20
135    Max value:    1.000000e-07
136    Default:      1.000000e-10
137    Description:  The RMS value of the estimated change in the total energy per step
138                  where we assume self consistency has been achieved.
139
140    Key name:     energy_output_units
141    Required:     no
142    Key type:     string
143    Expert:       No
144    Experimental: No
145    Default:      "Hartrees"
146    Allowed:      "Rydbergs" "Hartrees"
147    Description:  Units to be used when writing energy values to the output file.
148                  Hartrees or Rydbergs are available.
149
150    Key name:     exx_integrals_filepath
151    Required:     no
152    Key type:     string
153    Expert:       No
154    Experimental: No
155    Default:      "afqmc_rmg"
156    Allowed:
157    Description:  File/path for exact exchange integrals.
158
159    Key name:     exx_mode
160    Required:     no
161    Key type:     string
162    Expert:       No
163    Experimental: No
164    Default:      "Distributed fft"
165    Allowed:      "Local fft" "Distributed fft"
166    Description:  FFT mode for exact exchange computations.
167
168    Key name:     exxdiv_treatment
169    Required:     no
170    Key type:     string
171    Expert:       No
172    Experimental: No
173    Default:      "gygi-baldereschi"
174    Allowed:      "none" "gygi-baldereschi"
175    Description:  Exact exchange method for handling exx divergence at G=0.
176
177    Key name:     input_tddft_file
178    Required:     no
179    Key type:     string
180    Expert:       No
181    Experimental: No
182    Default:      "Waves/wave_tddft.out"
183    Allowed:
184    Description:  Input file/path to read wavefunctions and other binary data from
185                  on a restart.
186
187    Key name:     input_wave_function_file
188    Required:     no
189    Key type:     string
190    Expert:       No
191    Experimental: No
192    Default:      "Waves/wave.out"
193    Allowed:
194    Description:  Input file/path to read wavefunctions and other binary data from
195                  on a restart.
196
197    Key name:     interpolation_type
198    Required:     no
199    Key type:     string
200    Expert:       No
201    Experimental: No
202    Default:      "FFT"
203    Allowed:      "FFT" "prolong" "Cubic Polynomial"
204    Description:  Interpolation method for transferring data between the potential
205                  grid and the wavefunction grid. Mostly for diagnostic purposes.
206
207    Key name:     max_exx_steps
208    Required:     no
209    Key type:     integer
210    Expert:       No
211    Experimental: No
212    Min value:    1
213    Max value:    2147483647
214    Default:      100
215    Description:  Maximum number of self consistent steps to perform with hybrid
216                  functionals.
217
218    Key name:     max_scf_steps
219    Required:     no
220    Key type:     integer
221    Expert:       No
222    Experimental: No
223    Min value:    0
224    Max value:    2147483647
225    Default:      500
226    Description:  Maximum number of self consistent steps to perform. Inner loop for
227                  hybrid functionals.
228
229    Key name:     noncollinear
230    Required:     no
231    Key type:     boolean
232    Expert:       No
233    Experimental: No
234    Default:      "false"
235    Description:  if set true, calculate noncollinear
236
237    Key name:     nvme_orbitals
238    Required:     no
239    Key type:     boolean
240    Expert:       No
241    Experimental: No
242    Default:      "false"
243    Description:  Flag indicating whether or not orbitals should be mapped to disk.
244
245    Key name:     nvme_orbitals_filepath
246    Required:     no
247    Key type:     string
248    Expert:       No
249    Experimental: No
250    Default:      "Orbitals/"
251    Allowed:
252    Description:  File/path for runtime disk storage of orbitals.
253
254    Key name:     nvme_weights
255    Required:     no
256    Key type:     boolean
257    Expert:       No
258    Experimental: No
259    Default:      "false"
260    Description:  Flag indicating whether or not projector weights should be mapped
261                  to disk.
262
263    Key name:     nvme_weights_filepath
264    Required:     no
265    Key type:     string
266    Expert:       No
267    Experimental: No
268    Default:      "Weights/"
269    Allowed:
270    Description:  File/path for disk storage of projector weights.
271
272    Key name:     nvme_work
273    Required:     no
274    Key type:     boolean
275    Expert:       No
276    Experimental: No
277    Default:      "false"
278    Description:  Flag indicating whether or not work arrays should be mapped to
279                  disk.
280
281    Key name:     nvme_work_filepath
282    Required:     no
283    Key type:     string
284    Expert:       No
285    Experimental: No
286    Default:      "Work/"
287    Allowed:
288    Description:  File/path for disk storage of workspace.
289
290    Key name:     omp_threads_per_node
291    Required:     no
292    Key type:     integer
293    Expert:       No
294    Experimental: No
295    Min value:    0
296    Max value:    64
297    Default:      0
298    Description:  Number of Open MP threads each MPI process will use. A value of 0
299                  selects automatic setting.
300
301    Key name:     output_tddft_file
302    Required:     no
303    Key type:     string
304    Expert:       No
305    Experimental: No
306    Default:      "Waves/wave_tddft.out"
307    Allowed:
308    Description:  Output file/path to store wavefunctions and other binary data.
309
310    Key name:     output_wave_function_file
311    Required:     no
312    Key type:     string
313    Expert:       No
314    Experimental: No
315    Default:      "Waves/wave.out"
316    Allowed:
317    Description:  Output file/path to store wavefunctions and other binary data.
318
319    Key name:     pseudo_dir
320    Required:     no
321    Key type:     string
322    Expert:       No
323    Experimental: No
324    Default:      "."
325    Allowed:
326    Description:  Directory where pseudopotentials are stored.
327
328    Key name:     qfunction_filepath
329    Required:     no
330    Key type:     string
331    Expert:       No
332    Experimental: No
333    Default:      "Qfunctions/"
334    Allowed:
335    Description:  File/path for runtime disk storage of qfunctions.
336
337    Key name:     read_serial_restart
338    Required:     no
339    Key type:     boolean
340    Expert:       No
341    Experimental: No
342    Default:      "false"
343    Description:  Directs RMG to read from serial restart files. Normally used when
344                  changing the sprocessor topology used during a restart run
345
346    Key name:     rms_convergence_criterion
347    Required:     no
348    Key type:     double
349    Expert:       No
350    Experimental: No
351    Min value:    0.000000e+00
352    Max value:    1.000000e-03
353    Default:      1.000000e-07
354    Description:  The RMS value of the change in the total potential from step to
355                  step where we assume self consistency has been achieved.
356
357    Key name:     spinorbit
358    Required:     no
359    Key type:     boolean
360    Expert:       No
361    Experimental: No
362    Default:      "false"
363    Description:  if set true, calculate with spinorbit coupling
364
365    Key name:     start_mode
366    Required:     no
367    Key type:     string
368    Expert:       No
369    Experimental: No
370    Default:      "LCAO Start"
371    Allowed:      "Modified LCAO Start" "Restart TDDFT" "Start TDDFT" "Gaussian
372                  Start" "FIREBALL Start" "LCAO Start" "Restart From File" "Random
373                  Start"
374    Description:  Type of run.
375
376    Key name:     stress
377    Required:     no
378    Key type:     boolean
379    Expert:       No
380    Experimental: No
381    Default:      "false"
382    Description:  flag to control stress cacluation
383
384    Key name:     stress_convergence_criterion
385    Required:     no
386    Key type:     double
387    Expert:       No
388    Experimental: No
389    Min value:    0.000000e+00
390    Max value:    50.000000
391    Default:      0.500000
392    Description:  The stress criteria
393
394    Key name:     tddft_steps
395    Required:     no
396    Key type:     integer
397    Expert:       No
398    Experimental: No
399    Min value:    0
400    Max value:    2147483647
401    Default:      2000
402    Description:  Maximum number of tddft steps to perform.
403
404    Key name:     time_reversal
405    Required:     no
406    Key type:     boolean
407    Expert:       No
408    Experimental: No
409    Default:      "true"
410    Description:  if false, no k -> -k symmetry
411
412    Key name:     vdw_corr
413    Required:     no
414    Key type:     string
415    Expert:       No
416    Experimental: No
417    Default:      "None"
418    Allowed:      "DFT-D3" "DFT-D2" "Grimme-D2" "None"
419    Description:  Type of vdw correction
420
421    Key name:     vdwdf_kernel_filepath
422    Required:     no
423    Key type:     string
424    Expert:       No
425    Experimental: No
426    Default:      "vdW_kernel_table"
427    Allowed:
428    Description:  File/path for vdW_kernel_table data.
429
430    Key name:     wannier90
431    Required:     no
432    Key type:     boolean
433    Expert:       No
434    Experimental: No
435    Default:      "false"
436    Description:  set up informations for wannier90 interface
437
438    Key name:     wannier90_scdm_mu
439    Required:     no
440    Key type:     double
441    Expert:       No
442    Experimental: No
443    Min value:    -unlimited
444    Max value:    unlimited
445    Default:      0.000000e+00
446    Description:  when wannier90 is used to build wannier functions, the energy
447                  window parameter
448
449    Key name:     write_data_period
450    Required:     no
451    Key type:     integer
452    Expert:       No
453    Experimental: No
454    Min value:    5
455    Max value:    500
456    Default:      5
457    Description:  How often to write checkpoint files during the initial quench in
458                  units of SCF steps. During structural relaxations of molecular
459                  dynamics checkpoints are written each ionic step.
460
461    Key name:     write_eigvals_period
462    Required:     no
463    Key type:     integer
464    Expert:       No
465    Experimental: No
466    Min value:    1
467    Max value:    100
468    Default:      5
469    Description:  How often to output eigenvalues in units of scf steps.
470
471    Key name:     write_pseudopotential_plots
472    Required:     no
473    Key type:     boolean
474    Expert:       No
475    Experimental: No
476    Default:      "false"
477    Description:  Flag to indicate whether or not to write pseudopotential plots.
478
479    Key name:     write_qmcpack_restart
480    Required:     no
481    Key type:     boolean
482    Expert:       No
483    Experimental: No
484    Default:      "false"
485    Description:  If true then a QMCPACK restart file is written as well as a serial
486                  restart file.
487
488    Key name:     write_qmcpack_restart_localized
489    Required:     no
490    Key type:     boolean
491    Expert:       No
492    Experimental: No
493    Default:      "false"
494    Description:  If true then a QMCPACK restart file for localized orbitals
495
496    Key name:     write_serial_restart
497    Required:     no
498    Key type:     boolean
499    Expert:       No
500    Experimental: No
501    Default:      "false"
502    Description:  RMG normally writes parallel restart files. These require that
503                  restarts have the same processor topology. If write_serial_restart
504                  = "true" then RMG will also write a serial restart file that can
505                  be used with a different processor topology
506
507Cell parameter options
508
509    Key name:     atomic_coordinate_type
510    Required:     no
511    Key type:     string
512    Expert:       No
513    Experimental: No
514    Default:      "Absolute"
515    Allowed:      "Absolute" "Cell Relative"
516    Description:  Flag indicated whether or not atomic coordinates are absolute or
517                  cell relative.
518
519    Key name:     bravais_lattice_type
520    Required:     no
521    Key type:     string
522    Expert:       No
523    Experimental: No
524    Default:      "Orthorhombic Primitive"
525    Allowed:      "Tetragonal Primitive" "Cubic Body Centered" "Orthorhombic
526                  Primitive" "Cubic Face Centered" "Hexagonal Primitive" "Cubic
527                  Primitive" "None"
528    Description:  Bravais Lattice Type.
529
530    Key name:     cell_movable
531    Required:     no
532    Key type:     integer array
533    Expert:       No
534    Experimental: No
535    Default:      "0 0 0 0 0 0 0 0 0 "
536    Description:  9 numbers to control cell relaxation
537
538    Key name:     crds_units
539    Required:     no
540    Key type:     string
541    Expert:       No
542    Experimental: No
543    Default:      "Bohr"
544    Allowed:      "Angstrom" "Bohr"
545    Description:  Units for the atomic coordinates.
546
547    Key name:     grid_spacing
548    Required:     no
549    Key type:     double
550    Expert:       No
551    Experimental: No
552    Min value:    0.000000e+00
553    Max value:    unlimited
554    Default:      0.350000
555    Description:  Approximate grid spacing (bohr).
556
557    Key name:     kpoint_is_shift
558    Required:     no
559    Key type:     integer array
560    Expert:       No
561    Experimental: No
562    Default:      "0 0 0 "
563    Description:  Three-D layout of the kpoint shift.
564
565    Key name:     kpoint_mesh
566    Required:     no
567    Key type:     integer array
568    Expert:       No
569    Experimental: No
570    Default:      "1 1 1 "
571    Description:  Three-D layout of the kpoint mesh.
572
573    Key name:     lattice_units
574    Required:     no
575    Key type:     string
576    Expert:       No
577    Experimental: No
578    Default:      "Bohr"
579    Allowed:      "Angstrom" "Alat" "Bohr"
580    Description:  Units for the lattice vectors
581
582    Key name:     lattice_vector
583    Required:     no
584    Key type:     double array
585    Expert:       No
586    Experimental: No
587    Default:      "Not done yet"
588    Description:  Lattice vectors, a0, a1, a2
589
590    Key name:     potential_grid_refinement
591    Required:     no
592    Key type:     integer
593    Expert:       No
594    Experimental: No
595    Min value:    0
596    Max value:    4
597    Default:      0
598    Description:  Ratio of the potential grid density to the wavefunction grid
599                  density. For example if the wavefunction grid is (72,72,72) and
600                  potential_grid_refinement = "2" then the potential grid would be
601                  (144,144,144). The default value is 2 but it may sometimes be
602                  beneficial to adjust this. (For USPP the minimum value is also 2
603                  and it cannot be set lower. NCPP can be set to 1).
604
605    Key name:     processor_grid
606    Required:     no
607    Key type:     integer array
608    Expert:       No
609    Experimental: No
610    Default:      "1 1 1 "
611    Description:  Three-D (x,y,z) layout of the MPI processes.
612
613    Key name:     wavefunction_grid
614    Required:     no
615    Key type:     integer array
616    Expert:       No
617    Experimental: No
618    Default:      "1 1 1 "
619    Description:  Three-D (x,y,z) dimensions of the grid the wavefunctions are
620                  defined on.
621
622Pseudopotential related options
623
624    Key name:     atomic_orbital_type
625    Required:     no
626    Key type:     string
627    Expert:       No
628    Experimental: No
629    Default:      "delocalized"
630    Allowed:      "delocalized" "localized"
631    Description:  Atomic Orbital Type. Choices are localized and delocalized.
632
633    Key name:     energy_cutoff_parameter
634    Required:     no
635    Key type:     double
636    Expert:       Yes
637    Experimental: No
638    Min value:    0.600000
639    Max value:    1.000000
640    Default:      0.800000
641    Description:
642
643    Key name:     filter_dpot
644    Required:     no
645    Key type:     boolean
646    Expert:       Yes
647    Experimental: No
648    Default:      "false"
649    Description:  Flag indicating whether or not to filter density dependent
650                  potentials.
651
652    Key name:     filter_factor
653    Required:     no
654    Key type:     double
655    Expert:       Yes
656    Experimental: No
657    Min value:    0.060000
658    Max value:    1.000000
659    Default:      0.250000
660    Description:  Filtering factor.
661
662    Key name:     localize_localpp
663    Required:     no
664    Key type:     boolean
665    Expert:       No
666    Experimental: No
667    Default:      "true"
668    Description:  The local potential associated with a particular ion also decays
669                  rapidly in real-space with increasing r. As with beta projectors
670                  truncating the real-space representation for large cells can lead
671                  to significant computational savings with a small loss of accuracy
672                  but it should be set to false for small cells.
673
674    Key name:     localize_projectors
675    Required:     no
676    Key type:     boolean
677    Expert:       No
678    Experimental: No
679    Default:      "true"
680    Description:  The Beta function projectors for a particular ion decay rapidly in
681                  real-space with increasing r. For large cells truncating the
682                  real-space representation of the projector can lead to significant
683                  computational savings with a small loss of accuracy. For smaller
684                  cells the computational cost is the same for localized or
685                  delocalized projectors so it is better to set localize_projectors
686                  to false.
687
688    Key name:     max_nlradius
689    Required:     no
690    Key type:     double
691    Expert:       Yes
692    Experimental: No
693    Min value:    2.000000
694    Max value:    10000.000000
695    Default:      10000.000000
696    Description:  maximum radius for non-local projectors
697
698    Key name:     max_qradius
699    Required:     no
700    Key type:     double
701    Expert:       Yes
702    Experimental: No
703    Min value:    2.000000
704    Max value:    10000.000000
705    Default:      10000.000000
706    Description:  maximum radius for qfunc in ultra-pseudopotential
707
708    Key name:     min_nlradius
709    Required:     no
710    Key type:     double
711    Expert:       Yes
712    Experimental: No
713    Min value:    1.000000
714    Max value:    10000.000000
715    Default:      2.000000
716    Description:  minimum radius for non-local projectors
717
718    Key name:     min_qradius
719    Required:     no
720    Key type:     double
721    Expert:       Yes
722    Experimental: No
723    Min value:    1.000000
724    Max value:    10000.000000
725    Default:      2.000000
726    Description:  minimum radius for qfunc in ultra-pseudopotential
727
728    Key name:     projector_expansion_factor
729    Required:     no
730    Key type:     double
731    Expert:       Yes
732    Experimental: No
733    Min value:    0.500000
734    Max value:    3.000000
735    Default:      1.000000
736    Description:  When using localized projectors the radius can be adjusted with
737                  this parameter.
738
739    Key name:     pseudopotential
740    Required:     no
741    Key type:     formatted
742    Expert:       No
743    Experimental: No
744    Default:      ""
745    Allowed:
746    Description:  External pseudopotentials may be specfied with this input key. The
747                  format uses the atomic symbol followed by the pseudopotential file
748                  name. pseudopotential = "Ni Ni.UPF O O.UPF"
749
750Kohn Sham solver options
751
752    Key name:     davidson_max_steps
753    Required:     no
754    Key type:     integer
755    Expert:       No
756    Experimental: No
757    Min value:    5
758    Max value:    20
759    Default:      8
760    Description:  Maximum number of iterations for davidson diagonalization.
761
762    Key name:     davidson_multiplier
763    Required:     no
764    Key type:     integer
765    Expert:       No
766    Experimental: No
767    Min value:    0
768    Max value:    6
769    Default:      0
770    Description:  The davidson solver expands the eigenspace with the maximum
771                  expansion factor being set by the value of davidson_multiplier.
772                  Larger values often lead to faster convergence but because the
773                  computational cost of the davidson diagonalization step scales as
774                  the cube of the number of eigenvectors the optimal value based on
775                  the fastest time to solution depends on the number of orbitals. If
776                  not specified explicitly or set to 0 RMG uses the following
777                  algorithm to set the value.
778
779                  Number of orbitals <= 600 davidson_multiplier= "4"
780                  600 < Number of orbitals <= 900 davidson_multiplier = "3"
781                  Number of orbitals > 900 davidson_multiplier = "2"
782
783                  For very large problems the N^3 scaling makes even a factor of 2
784                  prohibitively costly and the multigrid solver is a better choice.
785
786    Key name:     kohn_sham_coarse_time_step
787    Required:     no
788    Key type:     double
789    Expert:       Yes
790    Experimental: No
791    Min value:    0.000000e+00
792    Max value:    1.200000
793    Default:      1.000000
794    Description:  Time step to use in the kohn-sham multigrid solver on the coarse
795                  levels.
796
797    Key name:     kohn_sham_fd_order
798    Required:     no
799    Key type:     integer
800    Expert:       Yes
801    Experimental: No
802    Min value:    6
803    Max value:    10
804    Default:      8
805    Description:  RMG uses finite differencing to represent the kinetic energy
806                  operator and the accuracy of the representation is controllable by
807                  the kohn_sham_fd_order parameter. The default is 8 and is fine for
808                  most purposes but higher accuracy is obtainable with 10th order at
809                  the cost of some additional computational expense.
810
811    Key name:     kohn_sham_mg_levels
812    Required:     no
813    Key type:     integer
814    Expert:       No
815    Experimental: No
816    Min value:    -1
817    Max value:    6
818    Default:      -1
819    Description:  Number of multigrid levels to use in the kohn-sham multigrid
820                  preconditioner.
821
822    Key name:     kohn_sham_mg_timestep
823    Required:     no
824    Key type:     double
825    Expert:       Yes
826    Experimental: No
827    Min value:    0.000000e+00
828    Max value:    2.000000
829    Default:      0.666667
830    Description:  timestep for multigrid correction.
831
832    Key name:     kohn_sham_mucycles
833    Required:     no
834    Key type:     integer
835    Expert:       No
836    Experimental: No
837    Min value:    1
838    Max value:    6
839    Default:      2
840    Description:  Number of mu (also known as W) cycles to use in the kohn-sham
841                  multigrid preconditioner.
842
843    Key name:     kohn_sham_post_smoothing
844    Required:     no
845    Key type:     integer
846    Expert:       Yes
847    Experimental: No
848    Min value:    1
849    Max value:    5
850    Default:      2
851    Description:  Number of global grid post-smoothing steps to perform after a
852                  multigrid preconditioner iteration.
853
854    Key name:     kohn_sham_pre_smoothing
855    Required:     no
856    Key type:     integer
857    Expert:       Yes
858    Experimental: No
859    Min value:    1
860    Max value:    5
861    Default:      2
862    Description:  Number of global grid pre-smoothing steps to perform before a
863                  multigrid preconditioner iteration.
864
865    Key name:     kohn_sham_solver
866    Required:     no
867    Key type:     string
868    Expert:       No
869    Experimental: No
870    Default:      "davidson"
871    Allowed:      "davidson" "multigrid"
872    Description:  RMG supports a pure multigrid Kohn-Sham solver as well as a
873                  multigrid preconditioned davidson solver. The davidson solver is
874                  usually better for smaller problems with the pure multigrid solver
875                  often being a better choice for very large problems.
876
877    Key name:     kohn_sham_time_step
878    Required:     no
879    Key type:     double
880    Expert:       Yes
881    Experimental: No
882    Min value:    0.000000e+00
883    Max value:    2.000000
884    Default:      0.660000
885    Description:  Smoothing timestep to use on the fine grid in the the kohn-sham
886                  multigrid preconditioner.
887
888    Key name:     unoccupied_tol_factor
889    Required:     no
890    Key type:     double
891    Expert:       Yes
892    Experimental: No
893    Min value:    1.000000
894    Max value:    100000.000000
895    Default:      1000.000000
896    Description:  When using the Davidson Kohn-Sham solver unoccupied states are
897                  converged to a less stringent tolerance than occupied orbitals
898                  with the ratio set by this parameter.
899
900Exchange correlation options
901
902    Key name:     exchange_correlation_type
903    Required:     no
904    Key type:     string
905    Expert:       No
906    Experimental: No
907    Default:      "AUTO_XC"
908    Allowed:      "hartree-fock" "vdw-df-c09" "sla+pw+pbe+vdw1" "VDW-DF" "vdw-df"
909                  "gaupbe" "B3LYP" "hse" "mgga tb09" "AUTO_XC" "m06l" "VDW-DF-CX"
910                  "tpss" "ev93" "optbk88" "sogga" "wc" "HSE" "HCTH" "hcth" "Q2D"
911                  "q2d" "PBESOL" "tb09" "b86bpbe" "PW86PBE" "PBE0" "MGGA TB09"
912                  "pw86pbe" "REVPBE" "pbe" "revpbe" "GGA PBE" "BLYP" "pbe0" "pbesol"
913                  "blyp" "PBE" "GGA XP CP" "pw91" "GGA XB CP" "TB09" "optb86b"
914                  "olyp" "BP" "GGA BLYP" "bp" "b3lyp" "LDA" "vdw-df-cx" "PW91" "PZ"
915                  "pz"
916    Description:  Most pseudopotentials specify the exchange correlation type they
917                  were generated with and the default value of AUTO_XC means that
918                  the type specified in the pseudopotial is what RMG will use. That
919                  can be overridden by specifying a value here.
920
921    Key name:     exx_convergence_criterion
922    Required:     no
923    Key type:     double
924    Expert:       No
925    Experimental: No
926    Min value:    1.000000e-12
927    Max value:    1.000000e-06
928    Default:      1.000000e-09
929    Description:  Convergence criterion for the EXX delta from step to step where we
930                  assume EXX consistency has been achieved.
931
932    Key name:     exx_fraction
933    Required:     no
934    Key type:     double
935    Expert:       No
936    Experimental: No
937    Min value:    -1.000000
938    Max value:    1.000000
939    Default:      -1.000000
940    Description:  when hybrid functional is used, the fraction of Exx
941
942    Key name:     vexx_fft_threshold
943    Required:     no
944    Key type:     double
945    Expert:       Yes
946    Experimental: No
947    Min value:    1.000000e-14
948    Max value:    0.100000
949    Default:      1.000000e-14
950    Description:  The value for the EXX delta where we switch from single to double
951                  precision ffts. Single precision ffts are generally accurate
952                  enough.
953
954    Key name:     x_gamma_extrapolation
955    Required:     no
956    Key type:     boolean
957    Expert:       No
958    Experimental: No
959    Default:      "true"
960    Description:  if set true, use exx extrapolation to gamma
961
962Orbital occupation options
963
964    Key name:     MP_order
965    Required:     no
966    Key type:     integer
967    Expert:       No
968    Experimental: No
969    Min value:    0
970    Max value:    5
971    Default:      2
972    Description:  order of Methefessel Paxton occupation.
973
974    Key name:     dos_broading
975    Required:     no
976    Key type:     double
977    Expert:       No
978    Experimental: No
979    Min value:    0.000000e+00
980    Max value:    1.000000
981    Default:      0.100000
982    Description:  For DOS with Gaussian broading method
983
984    Key name:     dos_method
985    Required:     no
986    Key type:     string
987    Expert:       No
988    Experimental: No
989    Default:      "tetrahedra"
990    Allowed:      "Gaussian" "tetrahedra"
991    Description:  tetrahedra or gauss smearing method for DOS calculation
992
993    Key name:     occupation_electron_temperature_eV
994    Required:     no
995    Key type:     double
996    Expert:       No
997    Experimental: No
998    Min value:    0.000000e+00
999    Max value:    2.000000
1000    Default:      0.040000
1001    Description:  Target electron temperature when not using fixed occupations.
1002
1003    Key name:     occupation_number_mixing
1004    Required:     no
1005    Key type:     double
1006    Expert:       No
1007    Experimental: No
1008    Min value:    0.000000e+00
1009    Max value:    1.000000
1010    Default:      1.000000
1011    Description:  Mixing parameter for orbital occupations when not using fixed
1012                  occupations.
1013
1014    Key name:     occupations_type
1015    Required:     no
1016    Key type:     string
1017    Expert:       No
1018    Experimental: No
1019    Default:      "Fermi Dirac"
1020    Allowed:      "Error Function" "Gaussian" "Fermi Dirac" "MethfesselPaxton" "Cold
1021                  Smearing" "Fixed"
1022    Description:  RMG supports several different ways of specifying orbital
1023                  occupations. For a spin polarized system one may specify the
1024                  occupations for up and down separately. In the case of a non-zero
1025                  electronic temperature these will be adjusted as the calculation
1026                  proceeds based on this setting.
1027
1028    Key name:     states_count_and_occupation
1029    Required:     no
1030    Key type:     string
1031    Expert:       No
1032    Experimental: No
1033    Default:      ""
1034    Allowed:
1035    Description:  Occupation string for states. Format for a system with 240
1036                  electrons and 20 unoccupied states would be. "120 2.0 20 0.0"
1037
1038    Key name:     states_count_and_occupation_spin_down
1039    Required:     no
1040    Key type:     string
1041    Expert:       No
1042    Experimental: No
1043    Default:      ""
1044    Allowed:
1045    Description:  Occupation string for spin down states. Format is the same as for
1046                  states_count_and_occupation. Total number of states must match
1047                  spin up occupation string.
1048
1049    Key name:     states_count_and_occupation_spin_up
1050    Required:     no
1051    Key type:     string
1052    Expert:       No
1053    Experimental: No
1054    Default:      ""
1055    Allowed:
1056    Description:  Occupation string for spin up states. Format is the same as for
1057                  states_count_and_occupation. Total number of states must match
1058                  spin down occupation string.
1059
1060    Key name:     unoccupied_states_per_kpoint
1061    Required:     no
1062    Key type:     integer
1063    Expert:       No
1064    Experimental: No
1065    Min value:    0
1066    Max value:    2147483647
1067    Default:      10
1068    Description:  The number of unoccupied orbitals. A value that is 15-20% of the
1069                  number of occupied orbitals generally works well.
1070
1071Charge density mixing options
1072
1073    Key name:     charge_broyden_order
1074    Required:     no
1075    Key type:     integer
1076    Expert:       No
1077    Experimental: No
1078    Min value:    1
1079    Max value:    10
1080    Default:      5
1081    Description:  Number of previous steps to use when Broyden mixing is used to
1082                  update the charge density.
1083
1084    Key name:     charge_broyden_scale
1085    Required:     no
1086    Key type:     double
1087    Expert:       No
1088    Experimental: No
1089    Min value:    0.000000e+00
1090    Max value:    1.000000
1091    Default:      0.500000
1092    Description:
1093
1094    Key name:     charge_density_mixing
1095    Required:     no
1096    Key type:     double
1097    Expert:       No
1098    Experimental: No
1099    Min value:    0.000000e+00
1100    Max value:    1.000000
1101    Default:      0.500000
1102    Description:  Proportion of the current charge density to replace with the new
1103                  density after each scf step when linear mixing is used.
1104
1105    Key name:     charge_mixing_type
1106    Required:     no
1107    Key type:     string
1108    Expert:       No
1109    Experimental: No
1110    Default:      "Pulay"
1111    Allowed:      "Broyden" "Pulay" "Linear"
1112    Description:  RMG supports Broyden, Pulay and Linear mixing When the davidson
1113                  Kohn-Sham solver is selected Broyden or Pulay are preferred. For
1114                  the multigrid solver Linear with potential acceleration is often
1115                  (but not always) the best choice.
1116
1117    Key name:     charge_pulay_Gspace
1118    Required:     no
1119    Key type:     boolean
1120    Expert:       No
1121    Experimental: No
1122    Default:      "false"
1123    Description:  if set true, charge density mixing the residual in G space
1124
1125    Key name:     charge_pulay_order
1126    Required:     no
1127    Key type:     integer
1128    Expert:       No
1129    Experimental: No
1130    Min value:    1
1131    Max value:    10
1132    Default:      5
1133    Description:  Number of previous steps to use when Pulay mixing is used to
1134                  update the charge density.
1135
1136    Key name:     charge_pulay_refresh
1137    Required:     no
1138    Key type:     integer
1139    Expert:       No
1140    Experimental: No
1141    Min value:    1
1142    Max value:    2147483647
1143    Default:      100
1144    Description:
1145
1146    Key name:     charge_pulay_scale
1147    Required:     no
1148    Key type:     double
1149    Expert:       No
1150    Experimental: No
1151    Min value:    0.000000e+00
1152    Max value:    1.000000
1153    Default:      0.500000
1154    Description:
1155
1156    Key name:     potential_acceleration_constant_step
1157    Required:     no
1158    Key type:     double
1159    Expert:       No
1160    Experimental: No
1161    Min value:    0.000000e+00
1162    Max value:    4.000000
1163    Default:      0.000000e+00
1164    Description:  When set to a non-zero value this parameter causes RMG to perform
1165                  a band by band update of the self-consistent potential during the
1166                  course of an SCF step when the multigrid kohn_sham_solver is
1167                  chosen. This means that updates to the lower energy orbitals are
1168                  incorporated into the SCF potential seen by the higher energy
1169                  orbitals as soon as they are computed. This can lead to faster
1170                  convergence and better stability for many systems. The option
1171                  should only be used with Linear mixing. Even when the davidson
1172                  solver is chosen this parameter may be used since the first few
1173                  steps with davidson usually uses the multigrid solver.
1174
1175Relaxation and Molecular dynamics options
1176
1177    Key name:     dynamic_time_counter
1178    Required:     no
1179    Key type:     integer
1180    Expert:       No
1181    Experimental: No
1182    Min value:    0
1183    Max value:    0
1184    Default:      0
1185    Description:
1186
1187    Key name:     dynamic_time_delay
1188    Required:     no
1189    Key type:     integer
1190    Expert:       No
1191    Experimental: No
1192    Min value:    5
1193    Max value:    5
1194    Default:      5
1195    Description:
1196
1197    Key name:     force_grad_order
1198    Required:     no
1199    Key type:     integer
1200    Expert:       No
1201    Experimental: No
1202    Min value:    0
1203    Max value:    12
1204    Default:      8
1205    Description:  Atomic forces may be computed to varying degrees of accuracy
1206                  depending on the requirements of a specific problem. A value of 0
1207                  implies highest accuracy which is obtained by using FFTs in place
1208                  of finite differencing.
1209
1210    Key name:     ionic_time_step
1211    Required:     no
1212    Key type:     double
1213    Expert:       No
1214    Experimental: No
1215    Min value:    0.000000e+00
1216    Max value:    unlimited
1217    Default:      50.000000
1218    Description:  Ionic time step for use in molecular dynamics and structure
1219                  optimizations.
1220
1221    Key name:     ionic_time_step_decrease
1222    Required:     no
1223    Key type:     double
1224    Expert:       No
1225    Experimental: No
1226    Min value:    0.000000e+00
1227    Max value:    1.000000
1228    Default:      0.500000
1229    Description:  Factor by which ionic timestep is decreased when dynamic timesteps
1230                  are enabled.
1231
1232    Key name:     ionic_time_step_increase
1233    Required:     no
1234    Key type:     double
1235    Expert:       No
1236    Experimental: No
1237    Min value:    1.000000
1238    Max value:    3.000000
1239    Default:      1.100000
1240    Description:  Factor by which ionic timestep is increased when dynamic timesteps
1241                  are enabled.
1242
1243    Key name:     max_ionic_time_step
1244    Required:     no
1245    Key type:     double
1246    Expert:       No
1247    Experimental: No
1248    Min value:    0.000000e+00
1249    Max value:    150.000000
1250    Default:      150.000000
1251    Description:  Maximum ionic time step to use for molecular dynamics or
1252                  structural optimizations.
1253
1254    Key name:     max_md_steps
1255    Required:     no
1256    Key type:     integer
1257    Expert:       No
1258    Experimental: No
1259    Min value:    0
1260    Max value:    2147483647
1261    Default:      100
1262    Description:  Maximum number of molecular dynamics steps to perform.
1263
1264    Key name:     md_integration_order
1265    Required:     no
1266    Key type:     string
1267    Expert:       No
1268    Experimental: No
1269    Default:      "5th Beeman-Velocity Verlet"
1270    Allowed:      "5th Beeman-Velocity Verlet" "3rd Beeman-Velocity Verlet" "2nd
1271                  Velocity Verlet"
1272    Description:  Integration order for molecular dynamics.
1273
1274    Key name:     md_nose_oscillation_frequency_THz
1275    Required:     no
1276    Key type:     double
1277    Expert:       No
1278    Experimental: No
1279    Min value:    0.000000e+00
1280    Max value:    unlimited
1281    Default:      15.590000
1282    Description:
1283
1284    Key name:     md_number_of_nose_thermostats
1285    Required:     no
1286    Key type:     integer
1287    Expert:       No
1288    Experimental: No
1289    Min value:    5
1290    Max value:    5
1291    Default:      5
1292    Description:  Number of Nose thermostats to use during Constant Volume and
1293                  Temperature MD.
1294
1295    Key name:     md_randomize_velocity
1296    Required:     no
1297    Key type:     boolean
1298    Expert:       No
1299    Experimental: No
1300    Default:      "true"
1301    Description:  The initial ionic velocities for a molecular dyanamics run are
1302                  randomly initialized to the target temperature.
1303
1304    Key name:     md_temperature
1305    Required:     no
1306    Key type:     double
1307    Expert:       No
1308    Experimental: No
1309    Min value:    0.000000e+00
1310    Max value:    unlimited
1311    Default:      300.000000
1312    Description:  Target MD Temperature.
1313
1314    Key name:     md_temperature_control
1315    Required:     no
1316    Key type:     string
1317    Expert:       No
1318    Experimental: No
1319    Default:      "Nose Hoover Chains"
1320    Allowed:      "Anderson Rescaling" "Nose Hoover Chains"
1321    Description:  Type of temperature control method to use in molecular dynamics.
1322
1323    Key name:     relax_dynamic_timestep
1324    Required:     no
1325    Key type:     boolean
1326    Expert:       No
1327    Experimental: No
1328    Default:      "false"
1329    Description:  Flag indicating whether or not to use dynamic timesteps in
1330                  relaxation mode.
1331
1332    Key name:     relax_mass
1333    Required:     no
1334    Key type:     string
1335    Expert:       No
1336    Experimental: No
1337    Default:      "Atomic"
1338    Allowed:      "Equal" "Atomic"
1339    Description:  Mass to use for structural relaxation, either atomic masses, or
1340                  the mass of carbon for all atoms.
1341
1342    Key name:     relax_max_force
1343    Required:     no
1344    Key type:     double
1345    Expert:       No
1346    Experimental: No
1347    Min value:    0.000000e+00
1348    Max value:    unlimited
1349    Default:      2.500000e-03
1350    Description:  Force value at which an ionic relaxation is considered to be
1351                  converged.
1352
1353    Key name:     relax_method
1354    Required:     no
1355    Key type:     string
1356    Expert:       No
1357    Experimental: No
1358    Default:      "Fast Relax"
1359    Allowed:      "LBFGS" "MD Min" "Quick Min" "FIRE" "Fast Relax"
1360    Description:  Type of relaxation method to use for structural optimizations.
1361
1362    Key name:     renormalize_forces
1363    Required:     no
1364    Key type:     boolean
1365    Expert:       No
1366    Experimental: No
1367    Default:      "true"
1368    Description:  Flag indicating whether or not to renormalize forces.
1369
1370    Key name:     tddft_time_step
1371    Required:     no
1372    Key type:     double
1373    Expert:       No
1374    Experimental: No
1375    Min value:    0.000000e+00
1376    Max value:    unlimited
1377    Default:      0.200000
1378    Description:  TDDFT time step for use in TDDFT mode
1379
1380Diagonalization options
1381
1382    Key name:     extra_random_lcao_states
1383    Required:     no
1384    Key type:     integer
1385    Expert:       No
1386    Experimental: No
1387    Min value:    0
1388    Max value:    2147483647
1389    Default:      0
1390    Description:  LCAO (Linear Combination of Atomic Orbitals) is the default
1391                  startup method for RMG. The atomic orbitals are obtained from the
1392                  pseudpotentials but in some cases better convergence may be
1393                  obtained by adding extra random wavefunctions in addition to the
1394                  atomic orbitals.
1395
1396    Key name:     folded_spectrum
1397    Required:     no
1398    Key type:     boolean
1399    Expert:       Yes
1400    Experimental: No
1401    Default:      "false"
1402    Description:  When the number of eigenvectors is large using folded_spectrum is
1403                  substantially faster than standard diagonalization. It also tends
1404                  to converge better for metallic systems. It works with the
1405                  multigrid kohn_sham_solver but not the davidson solver.
1406
1407    Key name:     folded_spectrum_iterations
1408    Required:     no
1409    Key type:     integer
1410    Expert:       Yes
1411    Experimental: No
1412    Min value:    0
1413    Max value:    20
1414    Default:      2
1415    Description:  Number of folded spectrum iterations to perform.
1416
1417    Key name:     folded_spectrum_width
1418    Required:     no
1419    Key type:     double
1420    Expert:       Yes
1421    Experimental: No
1422    Min value:    0.100000
1423    Max value:    1.000000
1424    Default:      0.300000
1425    Description:  Submatrix width to use as a fraction of the full spectrum. The
1426                  folded spectrum width ranges from 0.10 to 1.0. For insulators and
1427                  semiconductors a value of 0.3 is appropriate. For metals values
1428                  between 0.15 to 0.2 tend to be better. The default value is 0.3
1429
1430    Key name:     initial_diagonalization
1431    Required:     no
1432    Key type:     boolean
1433    Expert:       No
1434    Experimental: No
1435    Default:      "true"
1436    Description:  Perform initial subspace diagonalization.
1437
1438    Key name:     period_of_diagonalization
1439    Required:     no
1440    Key type:     integer
1441    Expert:       No
1442    Experimental: No
1443    Min value:    0
1444    Max value:    2147483647
1445    Default:      1
1446    Description:  Diagonalization period (per scf step). Mainly for debugging and
1447                  should not be changed for production.
1448
1449    Key name:     scalapack_block_factor
1450    Required:     no
1451    Key type:     integer
1452    Expert:       No
1453    Experimental: No
1454    Min value:    4
1455    Max value:    512
1456    Default:      32
1457    Description:  Block size to use with scalapack. Optimal value is dependent on
1458                  matrix size and system hardware.
1459
1460    Key name:     subdiag_driver
1461    Required:     no
1462    Key type:     string
1463    Expert:       No
1464    Experimental: No
1465    Default:      "auto"
1466    Allowed:      "elpa" "cusolver" "auto" "scalapack" "magma" "lapack"
1467    Description:  Driver type used for subspace diagonalization of the eigenvectors.
1468
1469Performance related options
1470
1471    Key name:     mpi_queue_mode
1472    Required:     no
1473    Key type:     boolean
1474    Expert:       No
1475    Experimental: No
1476    Default:      "true"
1477    Description:  Use mpi queue mode.
1478
1479    Key name:     non_local_block_size
1480    Required:     no
1481    Key type:     integer
1482    Expert:       No
1483    Experimental: No
1484    Min value:    64
1485    Max value:    40000
1486    Default:      512
1487    Description:  Block size to use when applying the non-local and S operators.
1488
1489    Key name:     preconditioner_threshold
1490    Required:     no
1491    Key type:     double
1492    Expert:       Yes
1493    Experimental: No
1494    Min value:    1.000000e-09
1495    Max value:    0.100000
1496    Default:      0.100000
1497    Description:  The RMS value of the change in the total potential where we switch
1498                  the preconditioner from single to double precision.
1499
1500    Key name:     require_huge_pages
1501    Required:     no
1502    Key type:     boolean
1503    Expert:       No
1504    Experimental: Yes
1505    Default:      "false"
1506    Description:  If set RMG assumes that sufficient huge pages are available. Bad
1507                  things may happen if this is not true.
1508
1509    Key name:     spin_manager_thread
1510    Required:     no
1511    Key type:     boolean
1512    Expert:       Yes
1513    Experimental: No
1514    Default:      "true"
1515    Description:  When mpi_queue_mode is enabled the manager thread spins instead of
1516                  sleeping.
1517
1518    Key name:     spin_worker_threads
1519    Required:     no
1520    Key type:     boolean
1521    Expert:       Yes
1522    Experimental: No
1523    Default:      "true"
1524    Description:  When mpi_queue_mode is enabled the worker threads spin instead of
1525                  sleeping.
1526
1527    Key name:     state_block_size
1528    Required:     no
1529    Key type:     integer
1530    Expert:       Yes
1531    Experimental: No
1532    Min value:    1
1533    Max value:    2147483647
1534    Default:      64
1535    Description:  state_block used in nlforce.
1536
1537    Key name:     use_alt_zgemm
1538    Required:     no
1539    Key type:     boolean
1540    Expert:       No
1541    Experimental: No
1542    Default:      "false"
1543    Description:  Flag indicating whether or not to use alternate zgemm
1544                  implementation.
1545
1546    Key name:     use_async_allreduce
1547    Required:     no
1548    Key type:     boolean
1549    Expert:       No
1550    Experimental: No
1551    Default:      "true"
1552    Description:  Use asynchronous allreduce if available.
1553
1554    Key name:     use_hwloc
1555    Required:     no
1556    Key type:     boolean
1557    Expert:       No
1558    Experimental: No
1559    Default:      "false"
1560    Description:  Use internal hwloc setup if available. If both this and use_numa
1561                  are true hwloc takes precedence.
1562
1563    Key name:     use_numa
1564    Required:     no
1565    Key type:     boolean
1566    Expert:       No
1567    Experimental: No
1568    Default:      "true"
1569    Description:  Use internal numa setup if available.
1570
1571LDAU options
1572
1573    Key name:     Hubbard_U
1574    Required:     no
1575    Key type:     formatted
1576    Expert:       No
1577    Experimental: No
1578    Default:      ""
1579    Allowed:
1580    Description:  Hubbard U parameter for each atomic species using the format
1581                  Hubbard_U="Ni 6.5"
1582
1583    Key name:     ldaU_mode
1584    Required:     no
1585    Key type:     string
1586    Expert:       No
1587    Experimental: No
1588    Default:      "None"
1589    Allowed:      "Simple" "None"
1590    Description:  Type of lda+u implementation.
1591
1592    Key name:     ldaU_radius
1593    Required:     no
1594    Key type:     double
1595    Expert:       No
1596    Experimental: No
1597    Min value:    1.000000
1598    Max value:    12.000000
1599    Default:      9.000000
1600    Description:  Max radius of atomic orbitals to be used in LDA+U projectors.
1601
1602Poisson solver options
1603
1604    Key name:     hartree_max_sweeps
1605    Required:     no
1606    Key type:     integer
1607    Expert:       No
1608    Experimental: No
1609    Min value:    5
1610    Max value:    100
1611    Default:      10
1612    Description:  Maximum number of hartree iterations to perform per scf step.
1613
1614    Key name:     hartree_min_sweeps
1615    Required:     no
1616    Key type:     integer
1617    Expert:       No
1618    Experimental: No
1619    Min value:    0
1620    Max value:    5
1621    Default:      5
1622    Description:  Minimum number of hartree iterations to perform per scf step.
1623
1624    Key name:     hartree_rms_ratio
1625    Required:     no
1626    Key type:     double
1627    Expert:       No
1628    Experimental: No
1629    Min value:    1000.000000
1630    Max value:    unlimited
1631    Default:      100000.000000
1632    Description:  Ratio between target RMS for get_vh and RMS total potential.
1633
1634    Key name:     poisson_coarse_time_step
1635    Required:     no
1636    Key type:     double
1637    Expert:       Yes
1638    Experimental: No
1639    Min value:    0.400000
1640    Max value:    1.000000
1641    Default:      0.800000
1642    Description:  Time step to use in the poisson multigrid solver on the coarse
1643                  levels.
1644
1645    Key name:     poisson_coarsest_steps
1646    Required:     no
1647    Key type:     integer
1648    Expert:       Yes
1649    Experimental: No
1650    Min value:    10
1651    Max value:    100
1652    Default:      25
1653    Description:  Number of smoothing steps to use on the coarsest level in the
1654                  hartree multigrid solver.
1655
1656    Key name:     poisson_finest_time_step
1657    Required:     no
1658    Key type:     double
1659    Expert:       Yes
1660    Experimental: No
1661    Min value:    0.400000
1662    Max value:    1.000000
1663    Default:      1.000000
1664    Description:  Time step to use in the poisson multigrid solver on the finest
1665                  level.
1666
1667    Key name:     poisson_mucycles
1668    Required:     no
1669    Key type:     integer
1670    Expert:       Yes
1671    Experimental: No
1672    Min value:    1
1673    Max value:    4
1674    Default:      3
1675    Description:  Number of mu (also known as W) cycles to use in the hartree
1676                  multigrid solver.
1677
1678    Key name:     poisson_post_smoothing
1679    Required:     no
1680    Key type:     integer
1681    Expert:       Yes
1682    Experimental: No
1683    Min value:    1
1684    Max value:    6
1685    Default:      1
1686    Description:  Number of global hartree grid post-smoothing steps to perform
1687                  after a multigrid iteration.
1688
1689    Key name:     poisson_pre_smoothing
1690    Required:     no
1691    Key type:     integer
1692    Expert:       Yes
1693    Experimental: No
1694    Min value:    1
1695    Max value:    6
1696    Default:      2
1697    Description:  Number of global hartree grid pre-smoothing steps to perform
1698                  before a multigrid iteration.
1699
1700    Key name:     poisson_solver
1701    Required:     no
1702    Key type:     string
1703    Expert:       No
1704    Experimental: No
1705    Default:      "pfft"
1706    Allowed:      "pfft" "multigrid"
1707    Description:  poisson solver.
1708
1709Testing options
1710
1711    Key name:     test_energy
1712    Required:     no
1713    Key type:     double
1714    Expert:       No
1715    Experimental: No
1716    Min value:    -1000000000.000000
1717    Max value:    1000000000.000000
1718    Default:      nan
1719    Description:  Expected final energy for testing.
1720
1721    Key name:     test_energy_tolerance
1722    Required:     no
1723    Key type:     double
1724    Expert:       No
1725    Experimental: No
1726    Min value:    1.000000e-08
1727    Max value:    1.000000e-04
1728    Default:      1.000000e-07
1729    Description:  Test final energy tolerance.
1730
1731Miscellaneous options
1732
1733    Key name:     E_POINTS
1734    Required:     no
1735    Key type:     integer
1736    Expert:       No
1737    Experimental: No
1738    Min value:    201
1739    Max value:    201
1740    Default:      201
1741    Description:
1742
1743    Key name:     Emax
1744    Required:     no
1745    Key type:     double
1746    Expert:       No
1747    Experimental: No
1748    Min value:    -100.000000
1749    Max value:    100.000000
1750    Default:      0.000000e+00
1751    Description:
1752
1753    Key name:     Emin
1754    Required:     no
1755    Key type:     double
1756    Expert:       No
1757    Experimental: No
1758    Min value:    -100.000000
1759    Max value:    100.000000
1760    Default:      -6.000000
1761    Description:
1762
1763    Key name:     ExxCholMax
1764    Required:     no
1765    Key type:     integer
1766    Expert:       No
1767    Experimental: No
1768    Min value:    1
1769    Max value:    64
1770    Default:      8
1771    Description:  maximum number of Exx integral cholesky vectors
1772
1773    Key name:     ExxIntCholosky
1774    Required:     no
1775    Key type:     boolean
1776    Expert:       No
1777    Experimental: No
1778    Default:      "true"
1779    Description:  if set true, Exx integrals are Cholesky factorized to 3-index
1780
1781    Key name:     alt_laplacian
1782    Required:     no
1783    Key type:     boolean
1784    Expert:       Yes
1785    Experimental: No
1786    Default:      "true"
1787    Description:  Flag indicating whether or not to use alternate laplacian weights
1788                  for some operators.
1789
1790    Key name:     boundary_condition_type
1791    Required:     no
1792    Key type:     string
1793    Expert:       No
1794    Experimental: No
1795    Default:      "Periodic"
1796    Allowed:      "Periodic"
1797    Description:  Boundary condition type Only periodic is currently implemented.
1798
1799    Key name:     charge_analysis
1800    Required:     no
1801    Key type:     string
1802    Expert:       No
1803    Experimental: No
1804    Default:      "Voronoi"
1805    Allowed:      "Voronoi" "None"
1806    Description:  Type of charge analysis to use. Only Voronoi deformation density
1807                  is currently available.
1808
1809    Key name:     charge_analysis_period
1810    Required:     no
1811    Key type:     integer
1812    Expert:       No
1813    Experimental: No
1814    Min value:    0
1815    Max value:    500
1816    Default:      0
1817    Description:  How often to perform and write out charge analysis.
1818
1819    Key name:     cube_pot
1820    Required:     no
1821    Key type:     boolean
1822    Expert:       No
1823    Experimental: No
1824    Default:      "false"
1825    Description:  if set true, total potential is printed out in cube format
1826
1827    Key name:     cube_rho
1828    Required:     no
1829    Key type:     boolean
1830    Expert:       No
1831    Experimental: No
1832    Default:      "true"
1833    Description:  if set true, charge density is printed out in cube format
1834
1835    Key name:     cube_states_list
1836    Required:     no
1837    Key type:     string
1838    Expert:       No
1839    Experimental: No
1840    Default:      ""
1841    Allowed:
1842    Description:  plot the states listed here
1843
1844    Key name:     cube_vh
1845    Required:     no
1846    Key type:     boolean
1847    Expert:       No
1848    Experimental: No
1849    Default:      "false"
1850    Description:  if set true, hatree potential is printed out in cube format
1851
1852    Key name:     dftd3_version
1853    Required:     no
1854    Key type:     integer
1855    Expert:       No
1856    Experimental: No
1857    Min value:    2
1858    Max value:    6
1859    Default:      3
1860    Description:  Grimme's DFT-D3 versions,
1861
1862    Key name:     dipole_correction
1863    Required:     no
1864    Key type:     integer array
1865    Expert:       No
1866    Experimental: No
1867    Default:      "0 0 0 "
1868    Description:  (1,1,1) for molecule, dipole correction in all directions.
1869
1870    Key name:     dipole_moment
1871    Required:     no
1872    Key type:     boolean
1873    Expert:       No
1874    Experimental: No
1875    Default:      "false"
1876    Description:  Turns on calculation of dipole moment for the entire cell.
1877
1878    Key name:     ecutrho
1879    Required:     no
1880    Key type:     double
1881    Expert:       No
1882    Experimental: No
1883    Min value:    0.000000e+00
1884    Max value:    10000.000000
1885    Default:      0.000000e+00
1886    Description:  ecut for rho in unit of Ry.
1887
1888    Key name:     ecutwfc
1889    Required:     no
1890    Key type:     double
1891    Expert:       No
1892    Experimental: No
1893    Min value:    0.000000e+00
1894    Max value:    10000.000000
1895    Default:      0.000000e+00
1896    Description:  ecut for wavefunctions in unit of Ry.
1897
1898    Key name:     electric_field_magnitude
1899    Required:     no
1900    Key type:     double
1901    Expert:       No
1902    Experimental: No
1903    Min value:    0.000000e+00
1904    Max value:    unlimited
1905    Default:      0.000000e+00
1906    Description:  Magnitude of external electric field.
1907
1908    Key name:     electric_field_vector
1909    Required:     no
1910    Key type:     double array
1911    Expert:       No
1912    Experimental: No
1913    Default:      "Not done yet"
1914    Description:  Components of the electric field.
1915
1916    Key name:     equal_initial_density
1917    Required:     no
1918    Key type:     boolean
1919    Expert:       No
1920    Experimental: No
1921    Default:      "false"
1922    Description:  Specifies whether to set initial up and down density to be equal.
1923
1924    Key name:     exx_int_flag
1925    Required:     no
1926    Key type:     boolean
1927    Expert:       No
1928    Experimental: No
1929    Default:      "false"
1930    Description:  if set true, calculate the exact exchange integrals
1931
1932    Key name:     fast_density
1933    Required:     no
1934    Key type:     boolean
1935    Expert:       No
1936    Experimental: No
1937    Default:      "true"
1938    Description:  Use a faster but less accurate method to generate the charge
1939                  density from the electronic wavefunctions. As the cutoff
1940                  (grid-density) increases this method improves in accuracy. This
1941                  option should be set to false if you receive warnings about
1942                  negative charge densities after interpolation.
1943
1944    Key name:     fd_allocation_limit
1945    Required:     no
1946    Key type:     integer
1947    Expert:       No
1948    Experimental: No
1949    Min value:    1024
1950    Max value:    262144
1951    Default:      65536
1952    Description:  Allocation sizes in finite difference routines less than this
1953                  value are stack rather than heap based.
1954
1955    Key name:     frac_symmetry
1956    Required:     no
1957    Key type:     boolean
1958    Expert:       No
1959    Experimental: No
1960    Default:      "true"
1961    Description:  For supercell calculation, one can disable the fractional
1962                  translation symmetry
1963
1964    Key name:     freeze_occupied
1965    Required:     no
1966    Key type:     boolean
1967    Expert:       No
1968    Experimental: Yes
1969    Default:      "false"
1970    Description:  Flag indicating whether or not to freeze the density and occupied
1971                  orbitals after a restart.
1972
1973    Key name:     gw_residual_convergence_criterion
1974    Required:     no
1975    Key type:     double
1976    Expert:       No
1977    Experimental: Yes
1978    Min value:    1.000000e-14
1979    Max value:    4.000000e-04
1980    Default:      1.000000e-06
1981    Description:  The max value of the residual for unoccupied orbitals when
1982                  performing a GW calculation.
1983
1984    Key name:     gw_residual_fraction
1985    Required:     no
1986    Key type:     double
1987    Expert:       No
1988    Experimental: Yes
1989    Min value:    0.000000e+00
1990    Max value:    1.000000
1991    Default:      0.900000
1992    Description:  The residual value specified by gw_residual_convergence_criterion
1993                  is applied to this fraction of the total spectrum.
1994
1995    Key name:     kohn_sham_ke_fft
1996    Required:     no
1997    Key type:     boolean
1998    Expert:       Yes
1999    Experimental: No
2000    Default:      "false"
2001    Description:  Special purpose flag which will force use of an FFT for the
2002                  kinetic energy operator.
2003
2004    Key name:     kpoint_distribution
2005    Required:     no
2006    Key type:     integer
2007    Expert:       No
2008    Experimental: No
2009    Min value:    -2147483647
2010    Max value:    2147483647
2011    Default:      -1
2012    Description:
2013
2014    Key name:     laplacian_autocoeff
2015    Required:     no
2016    Key type:     boolean
2017    Expert:       No
2018    Experimental: No
2019    Default:      "false"
2020    Description:  if set to true, we use LaplacianCoeff.cpp to generate coeff
2021
2022    Key name:     laplacian_offdiag
2023    Required:     no
2024    Key type:     boolean
2025    Expert:       No
2026    Experimental: No
2027    Default:      "false"
2028    Description:  if set to true, we use LaplacianCoeff.cpp to generate coeff
2029
2030    Key name:     lcao_use_empty_orbitals
2031    Required:     no
2032    Key type:     boolean
2033    Expert:       No
2034    Experimental: No
2035    Default:      "false"
2036    Description:  Some pseudopotentials contain unbound atomic orbitals and this
2037                  flag indicates whether or not they should be used for LCAO starts.
2038
2039    Key name:     md_steps_offset
2040    Required:     no
2041    Key type:     integer
2042    Expert:       No
2043    Experimental: No
2044    Min value:    0
2045    Max value:    0
2046    Default:      0
2047    Description:
2048
2049    Key name:     num_wanniers
2050    Required:     no
2051    Key type:     integer
2052    Expert:       No
2053    Experimental: No
2054    Min value:    0
2055    Max value:    2147483647
2056    Default:      0
2057    Description:  number of wannier functions to be used in wannier90
2058
2059    Key name:     output_rho_xsf
2060    Required:     no
2061    Key type:     boolean
2062    Expert:       No
2063    Experimental: No
2064    Default:      "false"
2065    Description:  Generate xsf format for electronic density.
2066
2067    Key name:     poisson_mg_levels
2068    Required:     no
2069    Key type:     integer
2070    Expert:       No
2071    Experimental: No
2072    Min value:    -1
2073    Max value:    6
2074    Default:      -1
2075    Description:  Number of multigrid levels to use in the hartree multigrid solver.
2076
2077    Key name:     restart_tddft
2078    Required:     no
2079    Key type:     boolean
2080    Expert:       No
2081    Experimental: No
2082    Default:      "false"
2083    Description:  restart TDDFT
2084
2085    Key name:     rmg2bgw
2086    Required:     no
2087    Key type:     boolean
2088    Expert:       No
2089    Experimental: Yes
2090    Default:      "false"
2091    Description:  Write wavefunction in G-space to BerkeleyGW WFN file.
2092
2093    Key name:     rmg_threads_per_node
2094    Required:     no
2095    Key type:     integer
2096    Expert:       No
2097    Experimental: No
2098    Min value:    0
2099    Max value:    64
2100    Default:      0
2101    Description:  Number of Multigrid/Davidson threads each MPI process will use. A
2102                  value of 0 means set automatically.
2103
2104    Key name:     scf_steps_offset
2105    Required:     no
2106    Key type:     integer
2107    Expert:       No
2108    Experimental: No
2109    Min value:    0
2110    Max value:    0
2111    Default:      0
2112    Description:
2113
2114    Key name:     sqrt_interpolation
2115    Required:     no
2116    Key type:     boolean
2117    Expert:       No
2118    Experimental: No
2119    Default:      "false"
2120    Description:  Flag indicating whether or not to use square root technique for
2121                  density interpolation.
2122
2123    Key name:     system_charge
2124    Required:     no
2125    Key type:     double
2126    Expert:       No
2127    Experimental: No
2128    Min value:    -unlimited
2129    Max value:    unlimited
2130    Default:      0.000000e+00
2131    Description:  Number of excess holes in the system (useful for doped systems).
2132                  Example, 2 means system is missing two electrons
2133
2134    Key name:     tddft_mode
2135    Required:     no
2136    Key type:     string
2137    Expert:       No
2138    Experimental: No
2139    Default:      "electric field"
2140    Allowed:      "point charge" "electric field"
2141    Description:  TDDFT mode
2142
2143    Key name:     tddft_qgau
2144    Required:     no
2145    Key type:     double
2146    Expert:       No
2147    Experimental: No
2148    Min value:    0.000000e+00
2149    Max value:    unlimited
2150    Default:      1.000000
2151    Description:  Gaussian parameter for point charge to Gaussian charge
2152
2153    Key name:     tddft_qpos
2154    Required:     no
2155    Key type:     double array
2156    Expert:       No
2157    Experimental: No
2158    Default:      "Not done yet"
2159    Description:  cartesian coordinate of the point charge for tddft
2160
2161    Key name:     total_scf_steps_offset
2162    Required:     no
2163    Key type:     integer
2164    Expert:       No
2165    Experimental: No
2166    Min value:    0
2167    Max value:    0
2168    Default:      0
2169    Description:
2170
2171    Key name:     use_cpdgemr2d
2172    Required:     no
2173    Key type:     boolean
2174    Expert:       No
2175    Experimental: No
2176    Default:      "true"
2177    Description:  if set to true, we use Cpdgemr2d to change matrix distribution
2178
2179    Key name:     use_symmetry
2180    Required:     no
2181    Key type:     boolean
2182    Expert:       No
2183    Experimental: No
2184    Default:      "true"
2185    Description:  For non-gamma point, always true, for gamma point, optional
2186
2187    Key name:     vdwdf_grid_type
2188    Required:     no
2189    Key type:     string
2190    Expert:       No
2191    Experimental: No
2192    Default:      "Coarse"
2193    Allowed:      "Fine" "Coarse"
2194    Description:  Type of grid to use when computing vdw-df correlation.
2195
2196    Key name:     verbose
2197    Required:     no
2198    Key type:     boolean
2199    Expert:       No
2200    Experimental: No
2201    Default:      "false"
2202    Description:  Flag for writing out extra information
2203
2204    Key name:     vxc_diag_nmax
2205    Required:     no
2206    Key type:     integer
2207    Expert:       No
2208    Experimental: No
2209    Min value:    1
2210    Max value:    10000
2211    Default:      1
2212    Description:  Maximum band index for diagonal Vxc matrix elements.
2213
2214    Key name:     vxc_diag_nmin
2215    Required:     no
2216    Key type:     integer
2217    Expert:       No
2218    Experimental: No
2219    Min value:    1
2220    Max value:    10000
2221    Default:      1
2222    Description:  Minimum band index for diagonal Vxc matrix elements.
2223
2224    Key name:     wannier90_scdm
2225    Required:     no
2226    Key type:     integer
2227    Expert:       No
2228    Experimental: No
2229    Min value:    -2147483647
2230    Max value:    2
2231    Default:      0
2232    Description:  use scdm method to set the trial wannier functions
2233
2234    Key name:     wannier90_scdm_sigma
2235    Required:     no
2236    Key type:     double
2237    Expert:       No
2238    Experimental: No
2239    Min value:    0.000000e+00
2240    Max value:    unlimited
2241    Default:      1.000000
2242    Description:  when wannier90 is used to build wannier functions, the energy
2243                  window parameter
2244
2245    Key name:     write_orbital_overlaps
2246    Required:     no
2247    Key type:     boolean
2248    Expert:       No
2249    Experimental: No
2250    Default:      "false"
2251    Description:  If true the orbital overlap matrix from successive MD steps is
2252                  written.
2253
2254    Key name:     write_pdos
2255    Required:     no
2256    Key type:     boolean
2257    Expert:       No
2258    Experimental: No
2259    Default:      "false"
2260    Description:  Flag to write partial density of states.
2261
2262    Key name:     z_average_output_mode
2263    Required:     no
2264    Key type:     string
2265    Expert:       No
2266    Experimental: No
2267    Default:      "None"
2268    Allowed:      "potential and charge density" "wave functions" "None"
2269    Description:  z_average_output_mode.
2270
2271'''
2272
2273undocumented_options = '''
2274Undocumented options
2275
2276    Key name:     use_bessel_projectors
2277    Required:     no
2278    Key type:     boolean
2279    Expert:       No
2280    Experimental: No
2281    Default:      "false"
2282
2283    Key name:     kpoints
2284    Required:     no
2285    Key type:     formatted
2286    Expert:       No
2287    Experimental: No
2288
2289    Key name:     kpoints_bandstructure
2290    Required:     no
2291    Key type:     formatted
2292    Expert:       No
2293    Experimental: No
2294
2295    Key name:     atoms
2296    Required:     no
2297    Key type:     formatted
2298    Expert:       No
2299    Experimental: No
2300
2301'''
2302
2303deprecated_options = '''
2304Deprecated options
2305
2306    Key name:     alpha
2307    Required:     no
2308    Key type:     double
2309    Expert:       No
2310    Experimental: No
2311
2312    Key name:     beta
2313    Required:     no
2314    Key type:     double
2315    Expert:       No
2316    Experimental: No
2317
2318    Key name:     gamma
2319    Required:     no
2320    Key type:     double
2321    Expert:       No
2322    Experimental: No
2323
2324    Key name:     length_units
2325    Required:     no
2326    Key type:     string
2327    Allowed:      "Angstrom" "Bohr"
2328    Expert:       No
2329    Experimental: No
2330
2331    Key name:     projector_mixing
2332    Required:     no
2333    Key type:     double
2334    Expert:       No
2335    Experimental: No
2336
2337'''
2338
2339raw_input_spec += undocumented_options
2340raw_input_spec += deprecated_options
2341
2342
2343
2344def read_string(v):
2345    return v.strip().strip('"')
2346#end def read_string
2347
2348truefalse_read = {'"true"':True,'"false"':False,'true':True,'false':False}
2349def read_boolean(v):
2350    return truefalse_read[v.lower()]
2351#end def read_boolean
2352
2353def read_integer(v):
2354    return int(v.strip().strip('"'))
2355#end def read_integer
2356
2357def read_double(v):
2358    return float(v.strip().strip('"'))
2359#end def read_double
2360
2361def read_integer_array(v):
2362    return np.array(v.strip().strip('"').split(),dtype=int)
2363#end def read_integer_array
2364
2365def read_double_array(v):
2366    return np.array(v.strip().strip('"').split(),dtype=float)
2367#end def read_double_array
2368
2369
2370def write_string(v):
2371    return '"'+v.strip()+'"'
2372#end def write_string
2373
2374truefalse_write = {True:'"true"',False:'"false"'}
2375def write_boolean(v):
2376    return truefalse_write[v]
2377#end def write_boolean
2378
2379def write_integer(v):
2380    return '"{}"'.format(v)
2381#end def write_integer
2382
2383double_fmt = '{: 16.8f}'
2384double_fmt_exp = '{: 16.8e}'
2385def write_double(v):
2386    vs = double_fmt.format(v).strip()
2387    if abs((float(vs)-v))>1e-6*abs(v):
2388        vs = double_fmt_exp.format(v).strip()
2389    #end if
2390    return '"'+vs+'"'
2391#end def write_double
2392
2393def write_integer_array(v):
2394    s = '"'
2395    if isinstance(v,np.ndarray):
2396        v = v.flatten()
2397    #end if
2398    for i in v:
2399        s+='{} '.format(i)
2400    #end for
2401    return s[:-1]+'"'
2402#end def write_integer_array
2403
2404def write_double_array(v):
2405    s = '"'
2406    if isinstance(v,np.ndarray):
2407        v = v.flatten()
2408    #end if
2409    for d in v:
2410        s+=double_fmt.format(d).strip()+' '
2411    #end for
2412    return s[:-1]+'"'
2413#end def write_double_array
2414
2415
2416rmg_value_types = obj({
2417    'string'        : (str  , np.string_),
2418    'boolean'       : (bool , np.bool_  ),
2419    'integer'       : (int  , np.int_   ),
2420    'double'        : (float, np.float_ ),
2421    'integer array' : (tuple,list,np.ndarray),
2422    'double array'  : (tuple,list,np.ndarray),
2423    })
2424
2425read_functions = obj({
2426    'string'        : read_string,
2427    'boolean'       : read_boolean,
2428    'integer'       : read_integer,
2429    'double'        : read_double,
2430    'integer array' : read_integer_array,
2431    'double array'  : read_double_array,
2432    })
2433
2434write_functions = obj({
2435    'string'        : write_string,
2436    'boolean'       : write_boolean,
2437    'integer'       : write_integer,
2438    'double'        : write_double,
2439    'integer array' : write_integer_array,
2440    'double array'  : write_double_array,
2441    })
2442
2443rmg_array_dtypes = obj({
2444    'integer array' : int,
2445    'double array'  : float,
2446    })
2447
2448
2449class RmgKeyword(DevBase):
2450    def __init__(self,key_spec,section_name):
2451        self.key_name     = None
2452        self.key_type     = None
2453        self.default      = None
2454        self.allowed      = None
2455        self.min_value    = None
2456        self.max_value    = None
2457        self.required     = None
2458        self.expert       = None
2459        self.experimental = None
2460        self.description  = None
2461
2462        self.value_type   = None
2463        self.array_dtype  = None
2464        self.section_name = section_name
2465
2466        spec = obj()
2467        name  = None
2468        value = None
2469        for line in key_spec.strip().splitlines():
2470            if ':' in line:
2471                if name is not None:
2472                    spec[name] = value
2473                #end if
2474                name,value = line.split(':',1)
2475                name  = name.strip().lower().replace(' ','_')
2476                value = value.strip()
2477            else:
2478                value += ' '+line.strip()
2479            #end if
2480        #end for
2481        if name is not None:
2482            spec[name] = value
2483        else:
2484            self.error('Invalid keyword specification text received.\nNo field names are present.\nInvalid spec: {}'.format(key_spec))
2485        #end if
2486
2487        for name,value in spec.items():
2488            if name not in self:
2489                kname = 'unknown'
2490                if 'key_name' in spec:
2491                    kname = spec.key_name
2492                #end if
2493                self.error('Unrecognized keyword specification field.\nKeyword: {}\nField name: {}\nField value: {}'.format(kname,name,value))
2494            #end if
2495            self[name] = value
2496        #end for
2497
2498        if self.key_name is None:
2499            self.error('Invalid keyword specification received.\nKey name must be defined.\nInvalid spec: {}'.format(key_spec))
2500        #end if
2501        if self.key_type is None:
2502            self.error('Invalid keyword specification received.\nKey type must be defined.\nInvalid spec: {}'.format(key_spec))
2503        #end if
2504
2505        if self.key_type=='formatted':
2506            return
2507        #end if
2508
2509        if self.key_type not in read_functions:
2510            self.error('Read function has not been implemented for key type "{}".'.format(self.key_type))
2511        #end if
2512        if self.key_type not in write_functions:
2513            self.error('Write function has not been implemented for key type "{}".'.format(self.key_type))
2514        #end if
2515
2516        read_function = read_functions[self.key_type]
2517
2518        yesno = dict(yes=True,no=False)
2519        if self.required is None:
2520            self.required = False
2521        else:
2522            self.required = yesno[self.required.lower()]
2523        #end if
2524        if self.expert is None:
2525            self.expert = False
2526        else:
2527            self.expert = yesno[self.expert.lower()]
2528        #end if
2529        if self.experimental is None:
2530            self.experimental = False
2531        else:
2532            self.experimental = yesno[self.experimental.lower()]
2533        #end if
2534        if self.min_value is not None:
2535            if 'unlimited' in self.min_value:
2536                self.min_value = None
2537            else:
2538                self.min_value = self.read(self.min_value)
2539            #end if
2540        #end if
2541        if self.max_value is not None:
2542            if 'unlimited' in self.max_value:
2543                self.max_value = None
2544            else:
2545                self.max_value = self.read(self.max_value)
2546            #end if
2547        #end if
2548        if self.default is not None and self.default!='"Not done yet"':
2549            self.default = self.read(self.default)
2550        #end if
2551        if self.allowed is not None:
2552            tokens = []
2553            i1 = -1
2554            i2 = -1
2555            for i,c in enumerate(self.allowed):
2556                if c=='"':
2557                    if i1==-1:
2558                        i1 = i
2559                    else:
2560                        i2 = i
2561                        tokens.append(self.read(self.allowed[i1:i2+1]))
2562                        i1 = -1
2563                        i2 = -1
2564                    #end if
2565                #end if
2566            #end for
2567            self.allowed = set(tokens)
2568            if len(self.allowed)==0:
2569                self.allowed = None
2570            #end if
2571        #end if
2572
2573        self.value_type = rmg_value_types[self.key_type]
2574        if self.key_type in rmg_array_dtypes:
2575            self.array_dtype  = rmg_array_dtypes[self.key_type]
2576        #end if
2577
2578    #end def __init__
2579
2580
2581    def read(self,value):
2582        return read_functions[self.key_type](value)
2583    #end def read
2584
2585
2586    def write(self,value):
2587        return write_functions[self.key_type](value)
2588    #end def write
2589
2590
2591    def assign(self,value):
2592        if not isinstance(value,self.value_type):
2593            self.error('cannot assign RMG keyword "{}".\nInvalid type encountered.\nType encoutered: {}\nType(s) expected: {}'.format(self.key_name,value.__class__.__name__,self.value_type))
2594        #end if
2595        if self.array_dtype is not None:
2596            return np.array(value,dtype=self.array_dtype)
2597        else:
2598            return value
2599        #end if
2600    #end def assign
2601
2602
2603    def valid(self,value,message=False):
2604        msg   = ''
2605        if not isinstance(value,self.value_type):
2606            msg += 'Keyword "{}" has the wrong type.\n  Type expected: {}\n  Type provided: {}\n'.format(self.key_name,self.key_type,value.__class__.__name__)
2607        else:
2608            if RmgInputSettings.enforce_min_value:
2609                if self.min_value is not None and value<self.min_value:
2610                    msg += 'Value for keyword "{}" is smaller than allowed.\n  Minimum value allowed: {}\n  Value provided: {}\n'.format(self.key_name,self.min_value,value)
2611                #end if
2612            #end if
2613            if RmgInputSettings.enforce_max_value:
2614                if self.max_value is not None and value>self.max_value:
2615                    self.warn('Value for keyword "{}" is larger than allowed.\n  Maximum value allowed: {}\n  Value provided: {}\n'.format(self.key_name,self.max_value,value))
2616                #end if
2617            #end if
2618            if RmgInputSettings.enforce_allowed:
2619                if self.allowed is not None and value not in self.allowed:
2620                    msg += 'Value for keyword "{}" is not allowed.\n  Value provided: {}\n  Allowed values: {}'.format(self.key_name,value,list(sorted(self.allowed)))
2621                #end if
2622            #end if
2623        #end if
2624        if not message:
2625            return len(msg)==0
2626        else:
2627            return len(msg)==0,msg
2628        #end if
2629    #end def valid
2630#end class RmgKeyword
2631
2632
2633
2634class FormattedRmgKeyword(RmgKeyword):
2635    def read(self,value):
2636        self.not_implemented()
2637    #end def read
2638
2639    def write(self,value):
2640        self.not_implemented()
2641    #end def write
2642
2643    def assign(self,value):
2644        self.not_implemented()
2645    #end def assign
2646
2647    def valid(self,value,message=False):
2648        valid = self.valid_no_msg(value)
2649        if not message:
2650            return valid
2651        else:
2652            return valid,'Data for keyword "{}" is invalid.\nInvalid value: {}'.format(self.key_name,value)
2653        #end if
2654    #end def valid
2655
2656    def valid_no_msg(self,value):
2657        self.not_implemented()
2658    #end def valid_no_msg
2659#end class FormattedRmgKeyword
2660
2661
2662
2663class FormattedTableRmgKeyword(FormattedRmgKeyword):
2664    array_options  = None
2665    array_types    = None
2666    exclude_fields = set()
2667
2668    def assign(self,value):
2669        if isinstance(value,str):
2670            return value
2671        elif isinstance(value,(dict,obj)):
2672            for k,v in value.items():
2673                if isinstance(v,(tuple,list)):
2674                    value[k] = np.array(v)
2675                #end if
2676            #end for
2677            return value
2678        else:
2679            self.error('cannot assign RMG keyword "{}".\nInvalid type encountered.\nType encoutered: {}\nType(s) expected: str,dict,obj'.format(self.key_name,value.__class__.__name__))
2680        #end if
2681    #end def assign
2682
2683    def valid_no_msg(self,value):
2684        cls = self.__class__
2685        if not isinstance(value,obj):
2686            return False
2687        #end if
2688        keys = set(value.keys())-set(cls.exclude_fields)
2689        match = False
2690        for key_set in cls.array_options:
2691            if keys==key_set:
2692                match = True
2693                break
2694            #end if
2695        #end if
2696        if not match:
2697            return False
2698        #end if
2699        lengths = [len(value[k]) for k in keys]
2700        if lengths[0]==0:
2701            return False
2702        #end if
2703        if len(set(lengths))!=1:
2704            return False
2705        #end if
2706        for k in keys:
2707            v = value[k]
2708            if not isinstance(v,np.ndarray):
2709                return False
2710            elif not isinstance(v.flatten()[0],cls.array_types[k]):
2711                return False
2712            #end if
2713        #end for
2714        return True
2715    #end def valid_no_msg
2716#end class FormattedTableRmgKeyword
2717
2718
2719
2720class PseudopotentialKeyword(FormattedTableRmgKeyword):
2721    array_options = [
2722        set(('species','pseudos')),
2723        ]
2724    array_types   = obj(
2725        species = rmg_value_types.string,
2726        pseudos = rmg_value_types.string,
2727        )
2728
2729    def read(self,value):
2730        d = np.array(value.split(),dtype=str)
2731        d.shape = len(d)//2,2
2732        species = d[:,0].flatten()
2733        pseudos = d[:,1].flatten()
2734        return obj(species=species,pseudos=pseudos)
2735    #end def read
2736
2737    def write(self,value):
2738        v = value
2739        s = '"\n'
2740        for (sp,p) in zip(v.species,v.pseudos):
2741            s += '{:<4} {}\n'.format(sp,p)
2742        #end for
2743        s += '"'
2744        return s
2745    #end def write
2746#end class PseudopotentialKeyword
2747
2748
2749
2750class KpointsKeyword(FormattedTableRmgKeyword):
2751    array_options = [
2752        set(('kpoints','weights')),
2753        ]
2754    array_types   = obj(
2755        kpoints = rmg_value_types.double,
2756        weights = rmg_value_types.double,
2757        )
2758
2759    def read(self,value):
2760        d = np.array(value.split(),dtype=float)
2761        d.shape = len(d)//4,4
2762        kpoints = d[:,:3]
2763        weights = d[:,-1].flatten()
2764        return obj(kpoints=kpoints,weights=weights)
2765    #end def read
2766
2767    def write(self,value):
2768        v = value
2769        s = '"\n'
2770        for (kp,w) in zip(v.kpoints,v.weights):
2771            s += '{: 16.12f} {: 16.12f} {: 16.12f} {: 16.12f}\n'.format(kp[0],kp[1],kp[2],w)
2772        #end for
2773        s += '"'
2774        return s
2775    #end def write
2776#end class KpointsKeyword
2777
2778
2779
2780class KpointsBandstructureKeyword(FormattedTableRmgKeyword):
2781    array_options = [
2782        set(('kpoints','counts','labels')),
2783        ]
2784    array_types   = obj(
2785        kpoints = rmg_value_types.double,
2786        counts  = rmg_value_types.integer,
2787        labels  = rmg_value_types.string,
2788        )
2789
2790    def read(self,value):
2791        d = np.array(value.split(),dtype=str)
2792        d.shape = len(d)//4,5
2793        kpoints = np.array(d[:,:3],dtype=float)
2794        counts  = np.array(d[:,3],dtype=int).flatten()
2795        labels  = d[:,-1].flatten()
2796        return obj(kpoints=kpoints,counts=counts,labels=labels)
2797    #end def read
2798
2799    def write(self,value):
2800        v = value
2801        s = '"\n'
2802        for (kp,c,l) in zip(v.kpoints,v.counts,v.labels):
2803            s += '{: 16.12f} {: 16.12f} {: 16.12f}  {:>3}  {}\n'.format(kp[0],kp[1],kp[2],c,l)
2804        #end for
2805        s += '"'
2806        return s
2807    #end def write
2808#end class KpointsBandstructureKeyword
2809
2810
2811
2812class AtomsKeyword(FormattedTableRmgKeyword):
2813
2814    formats = ('basic','movable','movable_moment','moment','spin_ratio','full_spin')
2815
2816    array_options = [
2817        set(('atoms','positions')),
2818        set(('atoms','positions','movable')),
2819        set(('atoms','positions','moments')),
2820        set(('atoms','positions','movable','moments')),
2821        set(('atoms','positions','movable','spin_ratio')),
2822        set(('atoms','positions','movable','spin_ratio','spin_theta','spin_phi')),
2823        ]
2824    array_types   = obj(
2825        atoms      = rmg_value_types.string,
2826        positions  = rmg_value_types.double,
2827        movable    = rmg_value_types.boolean,
2828        moments    = rmg_value_types.double,
2829        spin_ratio = rmg_value_types.double,
2830        spin_theta = rmg_value_types.double,
2831        spin_phi   = rmg_value_types.double,
2832        )
2833    exclude_fields = ['format']
2834
2835
2836    def read(self,value):
2837        # check if input data is empty
2838        value = value.strip()
2839        if len(value)==0:
2840            self.error('No data provided for "atoms".')
2841        #end if
2842
2843        # determine the number of values per line
2844        if '\n' in value:
2845            first,rest = value.split('\n',1)
2846        else:
2847            first = value
2848        #end if
2849        nvals = len(first.split())
2850
2851        # initial array parse of value table
2852        d = np.array(value.split(),dtype=str)
2853        d.shape = len(d)//nvals,nvals
2854
2855        # extract universal atom labels and positions
2856        atom_labels = d[:,0]
2857        atom_labels = atom_labels.flatten()
2858        positions   = np.array(d[:,1:4],dtype=float)
2859
2860        # extract remaining data and determine format
2861        v = obj(
2862            format    = None,
2863            atoms     = atom_labels,
2864            positions = positions,
2865            )
2866
2867        boolset = set(['0','1'])
2868        invalid_format = False
2869        if nvals==4:
2870            v.format = 'basic'
2871        elif nvals==5:
2872            if len(set(d[:,4])-boolset)==0:
2873                v.movable = np.array(d[:,4],dtype=bool)
2874                v.format  = 'movable'
2875            else:
2876                try:
2877                    v.moments = np.array(d[:,4],dtype=float)
2878                    v.format  = 'moment'
2879                except:
2880                    invalid_format = True
2881                #end try
2882            #end if
2883        elif nvals==6:
2884            try:
2885                v.movable = np.array(d[:,4],dtype=bool)
2886                v.moments = np.array(d[:,5],dtype=float)
2887                v.format  = 'movable_moment'
2888            except:
2889                invalid_format = True
2890            #end try
2891        elif nvals==8:
2892            try:
2893                assert(len(set(d[:,4:7].flatten())-boolset)==0)
2894                v.movable    = np.array(d[:,4:7],dtype=bool)
2895                v.spin_ratio = np.array(d[:,7],dtype=float)
2896                v.format     = 'spin_ratio'
2897            except:
2898                invalid_format = True
2899            #end try
2900        elif nvals==10:
2901            try:
2902                assert(len(set(d[:,4:7].flatten())-boolset)==0)
2903                v.movable    = np.array(d[:,4:7],dtype=bool)
2904                v.spin_ratio = np.array(d[:,7],dtype=float)
2905                v.spin_theta = np.array(d[:,8],dtype=float)
2906                v.spin_phi   = np.array(d[:,9],dtype=float)
2907                v.format     = 'full_spin'
2908            except:
2909                invalid_format = True
2910            #end try
2911        #end if
2912
2913        if invalid_format:
2914            self.error('Failed to read atoms data.\nPlease check the formatting:\n{}'.format(value))
2915        elif v.format is None or v.format not in AtomsKeyword.formats:
2916            self.error('Failed to read atoms data.\nThis is a developer error.\nPlease contact the developers.')
2917        #end if
2918
2919        return v
2920    #end def read
2921
2922    def write(self,value):
2923        v = value
2924        s = '"\n'
2925        if v.format=='basic':
2926            for (a,p) in zip(v.atoms,v.positions):
2927                s += '{:<4} {: 16.12f} {: 16.12f} {: 16.12f}\n'.format(a,p[0],p[1],p[2])
2928            #end for
2929        elif v.format=='movable':
2930            for (a,p,m) in zip(v.atoms,v.positions,v.movable):
2931                s += '{:<4} {: 16.12f} {: 16.12f} {: 16.12f}  {}\n'.format(a,p[0],p[1],p[2],int(m))
2932            #end for
2933        elif v.format=='moment':
2934            for (a,p,m) in zip(v.atoms,v.positions,v.moments):
2935                s += '{:<4} {: 16.12f} {: 16.12f} {: 16.12f}  {: 6.4f}\n'.format(a,p[0],p[1],p[2],m)
2936            #end for
2937        elif v.format=='movable_moment':
2938            for (a,p,mv,mo) in zip(v.atoms,v.positions,v.movable,v.moments):
2939                s += '{:<4} {: 16.12f} {: 16.12f} {: 16.12f}  {}  {: 6.4f}\n'.format(a,p[0],p[1],p[2],int(mv),mo)
2940            #end for
2941        elif v.format=='spin_ratio':
2942            for (a,p,m,s) in zip(v.atoms,v.positions,v.movable,v.spin_ratio):
2943                s += '{:<4} {: 16.12f} {: 16.12f} {: 16.12f} {} {} {} {: 6.4f}\n'.format(a,p[0],p[1],p[2],int(m[0]),int(m[1]),int(m[2]),s)
2944            #end for
2945        elif v.format=='full_spin':
2946            for (a,p,m,sr,st,sp) in zip(v.atoms,v.positions,v.movable,v.spin_ratio,v.spin_theta,v.spin_phi):
2947                s += '{:<4} {: 16.12f} {: 16.12f} {: 16.12f} {} {} {} {: 6.4f} {: 6.2f} {: 6.2f}\n'.format(a,p[0],p[1],p[2],int(m[0]),int(m[1]),int(m[2]),sr,st,sp)
2948            #end for
2949        else:
2950            self.error('Invalid atoms format encountered on write.\nInvalid format: {}\nValid options are: {}'.format(v.format,self.formats))
2951        #end if
2952        s += '"'
2953        return s
2954    #end def write
2955#end class AtomsKeyword
2956
2957
2958
2959class HubbardUKeyword(RmgKeyword):
2960    def read(self,value):
2961        v = obj()
2962        tokens = read_string(value).split()
2963        for a,u in zip(tokens[::2],tokens[1::2]):
2964            v[a] = float(u)
2965        #end for
2966        return v
2967    #end def read
2968
2969    def write(self,value):
2970        s = ''
2971        for a in sorted(value.keys()):
2972            s += ' {} {}'.format(a,value[a])
2973        #end for
2974        return write_string(s)
2975    #end def write
2976
2977    def assign(self,value):
2978        if isinstance(value,str):
2979            return value
2980        elif isinstance(value,(dict,obj)):
2981            return obj(value)
2982        else:
2983            self.error('cannot assign RMG keyword "{}".\nInvalid type encountered.\nType encoutered: {}\nType(s) expected: str,dict,obj'.format(self.key_name,value.__class__.__name__))
2984        #end if
2985    #end def assign
2986
2987    def valid(self,value,message=False):
2988        valid = True
2989        for k,v in value.items():
2990            if not isinstance(k,rmg_value_types.string):
2991                valid = False
2992                break
2993            elif not isinstance(v,rmg_value_types.double):
2994                valid = False
2995                break
2996            #end if
2997        #end for
2998        if not message:
2999            return valid
3000        else:
3001            return valid,'Data for keyword "{}" is invalid.\nInvalid value: {}'.format(self.key_name,value)
3002        #end if
3003    #end def valid
3004#end class HubbardUKeyword
3005
3006
3007formatted_keywords = obj(
3008    pseudopotential       = PseudopotentialKeyword,
3009    kpoints               = KpointsKeyword,
3010    kpoints_bandstructure = KpointsBandstructureKeyword,
3011    atoms                 = AtomsKeyword,
3012    Hubbard_U             = HubbardUKeyword,
3013    )
3014
3015
3016
3017class RmgInputSpec(DevBase):
3018    def __init__(self):
3019        spec = raw_input_spec.strip()
3020
3021        blocks = spec.split('\n\n')
3022
3023        self.section_order    = []
3024        self.section_labels   = obj()
3025        self.section_contents = obj()
3026        self.keywords         = obj()
3027
3028        section  = None
3029        sec_cont = None
3030        for b in blocks:
3031            if ':' not in b:
3032                b = b.strip().lower()
3033                if b.endswith('options'):
3034                    sec_cont = []
3035                    section  = b.replace(' options','').strip().replace('  ',' ').replace(' ','_')
3036                    self.section_order.append(section)
3037                    self.section_labels[section]   = b
3038                    self.section_contents[section] = sec_cont
3039                #end if
3040            else:
3041                k = RmgKeyword(b,section)
3042                if k.key_type=='formatted':
3043                    if k.key_name not in formatted_keywords:
3044                        self.error('unrecognized formatted keyword: "{}"'.format(k.key_name))
3045                    #end if
3046                    k = formatted_keywords[k.key_name](b,section)
3047                #end if
3048                self.keywords[k.key_name] = k
3049                sec_cont.append(k.key_name)
3050            #end if
3051        #end for
3052    #end def __init__
3053#end class RmgInputSpec
3054
3055input_spec = RmgInputSpec()
3056
3057
3058class RmgCalcModes(DevBase):
3059    def __init__(self):
3060        self.full_calc = obj(
3061            scf         = 'Quench Electrons',
3062            exx         = 'Exx Only',
3063            neb         = 'NEB Relax',
3064            band        = 'Band Structure Only',
3065            relax       = 'Relax Structure',
3066            dimer_relax = 'Dimer Relax',
3067            md_PE       = 'Constant Pressure And Energy',
3068            md_TE       = 'Constant Temperature And Energy',
3069            md_VE       = 'Constant Volume And Energy',
3070            tddft       = 'TDDFT',
3071            plot        = 'Plot',
3072            psi_plot    = 'Psi Plot',
3073            )
3074
3075        self.short_calc = obj()
3076        for k,v in self.full_calc.items():
3077            self.short_calc[v] = k
3078        #end for
3079        self.full_calc_modes  = set(self.full_calc.values())
3080        self.short_calc_modes = set(self.short_calc.values())
3081    #end def __init__
3082
3083    def is_full_mode(self,mode):
3084        return mode in self.full_calc_modes
3085    #end def is_full_mode
3086
3087    def is_short_mode(self,mode):
3088        return mode in self.short_calc_modes
3089    #end def is_short_mode
3090
3091    def full_mode(self,short_mode):
3092        mode = None
3093        if short_mode in self.full_calc:
3094            mode = self.full_calc[short_mode]
3095        #end if
3096        return mode
3097    #end def full_mode
3098
3099    def short_mode(self,full_mode):
3100        mode = None
3101        if full_mode in self.short_calc:
3102            mode = self.short_calc[full_mode]
3103        #end if
3104        return mode
3105    #end def short_mode
3106
3107    def mode_match(self,text,short=False):
3108        mode = None
3109        text = text.lower()
3110        for full_mode in self.full_calc_modes:
3111            if full_mode.lower() in text:
3112                if not short:
3113                    mode = full_mode
3114                else:
3115                    mode = self.short_mode(full_mode)
3116                #end if
3117                break
3118            #end if
3119        #end for
3120        return mode
3121    #end def mode_match
3122
3123#end class RmgCalcModes
3124
3125rmg_modes = RmgCalcModes()
3126
3127
3128
3129
3130
3131
3132
3133class RmgInput(SimulationInput):
3134    def __init__(self,filepath=None):
3135        if filepath is not None:
3136            self.read(filepath)
3137        #end if
3138    #end def __init__
3139
3140
3141    def assign(self,**values):
3142        unrecognized = []
3143        for k,v in values.items():
3144            if k in input_spec.keywords:
3145                if isinstance(v,(str,np.string_)):
3146                    self[k] = input_spec.keywords[k].read(v)
3147                else:
3148                    self[k] = input_spec.keywords[k].assign(v)
3149                #end if
3150            else:
3151                unrecognized.append(k)
3152            #end if
3153        #end for
3154        if len(unrecognized)>0:
3155            unrec = obj(values).obj(unrecognized)
3156            self.error('Unrecognized keywords encountered during assignment.\nUnrecognized keywords: {}\nCorresponding values:\n{}'.format(list(sorted(unrecognized)),unrec))
3157        #end if
3158    #end def assign
3159
3160
3161    def read_text(self,contents,filepath=None):
3162        # remove comments and whitespace
3163        text = ''
3164        for line in contents.splitlines():
3165            i = line.find('#')
3166            if i!=-1:
3167                line = line[:i]
3168            #end if
3169            ls = line.strip()
3170            if len(ls)>0:
3171                text += ls+'\n'
3172            #end if
3173        #end for
3174        text = text.strip()
3175
3176        # separate keywords and values
3177        values = obj()
3178        whitespace = ' \t\n'
3179        icur = 0
3180        k = 'some key'
3181        while k is not None:
3182            k  = None
3183            ie = text.find('=',icur)
3184            if ie!=-1:
3185                k   = text[icur:ie].strip()
3186                iv1 = text.find('"',ie)
3187                if iv1!=-1:
3188                    iv2 = text.find('"',iv1+1)
3189                    if iv2!=-1:
3190                        v         = text[iv1+1:iv2]
3191                        values[k] = v
3192                        icur      = iv2+1
3193                    #end if
3194                #end if
3195            #end if
3196        #end while
3197
3198        # read the keyword values, checking for unrecognized ones
3199        self.assign(**values)
3200    #end def read_text
3201
3202
3203    def write_text(self,filepath=None):
3204        if RmgInputSettings.check_on_write:
3205            self.check_valid()
3206        #end if
3207        text = ''
3208        for section_name in input_spec.section_order:
3209            present = False
3210            for k in input_spec.section_contents[section_name]:
3211                if k in self:
3212                    if not present:
3213                        text += '\n\n# '+input_spec.section_labels[section_name]+'\n\n'
3214                        present = True
3215                    #end if
3216                    kw = input_spec.keywords[k]
3217                    text += '{:<22} = {}\n'.format(kw.key_name,kw.write(self[k]))
3218                #end if
3219            #end for
3220        #end for
3221        return text.lstrip()
3222    #end def write_text
3223
3224
3225    def check_valid(self,exit=True):
3226        msg = ''
3227        allowed = set(input_spec.keywords.keys())
3228        present = set(self.keys())
3229        unrecognized = present-allowed
3230        if len(unrecognized)>0:
3231            msg += 'Unrecognized keywords encountered.\n  Unrecognized keywords: {}\n  Valid keywords are: {}\n'.format(list(sorted(unrecognized)),list(sorted(allowed)))
3232        #end if
3233        recognized = present-unrecognized
3234        for k in sorted(recognized):
3235            kval,m = input_spec.keywords[k].valid(self[k],message=True)
3236            if not kval:
3237                msg += m+'\n'
3238            #end if
3239        #end if
3240        if len(msg)>0 and exit:
3241            self.log(msg)
3242            self.error('Input is invalid.\nPlease see messages above for specific issues.')
3243        #end if
3244        return len(msg)==0
3245    #end def check_valid
3246
3247
3248    def is_valid(self):
3249        return self.check_valid(exit=False)
3250    #end def is_valid
3251
3252
3253    def return_structure(self,units='B'):
3254        axes       = self.get('lattice_vector',None)
3255        axes_unit  = self.get('lattice_units','bohr')
3256        lattice    = self.get('bravais_lattice_type','orthorhombic primitive')
3257        a          = self.get('a_length',0.0)
3258        b          = self.get('b_length',0.0)
3259        c          = self.get('c_length',0.0)
3260
3261        coord_type = self.get('atomic_coordinate_type','absolute')
3262        coord_unit = self.get('crds_units','bohr')
3263        atom_data  = self.get('atoms',obj())
3264        atoms      = atom_data.get('atoms',None)
3265        positions  = atom_data.get('positions',None)
3266
3267        unit_dict = dict(angstrom='A',bohr='B')
3268        coord_unit = unit_dict[coord_unit.lower()]
3269        axes_unit  = unit_dict[axes_unit.lower()]
3270
3271        if axes is not None:
3272            axes = np.array(axes,dtype=float)
3273        else:
3274            lattice_orig = lattice
3275            lattice = lattice.lower()
3276            if lattice=='cubic primitive':
3277                axes = np.diag((a,a,a))
3278            elif lattice=='tetragonal primitive':
3279                axes = np.diag((a,a,c))
3280            elif lattice=='orthorhombic primitive':
3281                axes = np.diag((a,b,c))
3282            elif lattice=='cubic body centered':
3283                axes = 0.5*a*np.array([[ 1, 1,-1],
3284                                       [-1, 1, 1],
3285                                       [ 1,-1, 1]],dtype=float)
3286            elif lattice=='cubic face centered':
3287                axes = 0.5*a*np.array([[ 1, 1, 0],
3288                                       [ 0, 1, 1],
3289                                       [ 1, 0, 1]],dtype=float)
3290            elif lattice=='hexagonal primitive':
3291                axes = np.array([[   a,              0, 0],
3292                                 [-a/2, np.sqrt(3)/2*a, 0],
3293                                 [   0,              0, c]],dtype=float)
3294            else:
3295                # cubic body centered, hexagonal primitive not yet supported
3296                self.error('Structure extraction failed.\nLattice type "{}" is currently unsupported.'.format(lattice_orig))
3297            #end if
3298        #end if
3299        axes = convert(axes,axes_unit,units)
3300
3301        if atoms is None or positions is None:
3302            self.error('Structure extraction failed.\nEither atoms or positions could not be obtained.')
3303        #end if
3304        atoms     = np.array(atoms,dtype=object)
3305        positions = np.array(positions,dtype=float)
3306        if coord_type.lower()=='cell relative':
3307            positions = np.dot(positions,axes)
3308        else:
3309            positions = convert(positions,coord_unit,units)
3310        #end if
3311
3312        s = generate_structure(
3313            units = units,
3314            axes  = axes,
3315            elem  = atoms,
3316            pos   = positions,
3317            )
3318
3319        return s
3320    #end def return_structure
3321#end class RmgInput
3322
3323
3324
3325
3326def generate_rmg_input(**kwargs):
3327    selector = kwargs.pop('input_type','generic')
3328    if selector=='generic':
3329        return generate_any_rmg_input(**kwargs)
3330    else:
3331        RmgInput.class_error('Input type "{}" has not been implemented for RMG input generation.'.format(selector))
3332    #end if
3333#end def generate_rmg_input
3334
3335
3336
3337generate_any_defaults = obj(
3338    none  = obj(),
3339    basic = obj(
3340        use_folded             = True,
3341        virtual_frac           = 0.20,
3342        ),
3343    #qmc   = obj(
3344    #    use_folded             = True,
3345    #    ),
3346    )
3347
3348def generate_any_rmg_input(**kwargs):
3349    loc = 'generate_rmg_input'
3350
3351    # set default values
3352    defaults = kwargs.pop('defaults','basic')
3353    kw = obj(**kwargs)
3354    kw.set_optional(generate_any_defaults[defaults])
3355
3356    # extract keywords not appearing in RMG input file
3357    text            = kw.delete_optional('text'           , None   )
3358    wf_grid_spacing = kw.delete_optional('wf_grid_spacing', None   )
3359    pseudos         = kw.delete_optional('pseudos'        , None   )
3360    system          = kw.delete_optional('system'         , None   )
3361    copy_system     = kw.delete_optional('copy_system'    , True   )
3362    use_folded      = kw.delete_optional('use_folded'     , False  )
3363    virtual_frac    = kw.delete_optional('virtual_frac'   , None   )
3364    spin_polarized  = kw.delete_optional('spin_polarized' , None   )
3365    default_units   = kw.delete_optional('default_units'  , 'bohr' )
3366
3367    default_units = dict(
3368        a        = 'angstrom',
3369        b        = 'bohr',
3370        angstrom = 'angstrom',
3371        bohr     = 'bohr'
3372        )[default_units.lower()]
3373
3374    rmg_units_map = obj(
3375        angstrom = 'Angstrom',
3376        bohr     = 'Bohr',
3377        alat     = 'Alat',
3378        a        = 'Angstrom',
3379        b        = 'Bohr',
3380        )
3381
3382    # generate RMG input
3383    ri = RmgInput()
3384    if text is not None:
3385        ri.read_text(text)
3386    #end if
3387    ri.assign(**kw)
3388
3389    # incorporate pseudopotentials details provided via "pseudos"
3390    if pseudos is not None:
3391        species = []
3392        pps     = []
3393        for ppname in pseudos:
3394            label,element = pp_elem_label(ppname,guard=True)
3395            species.append(element)
3396            pps.append(ppname)
3397        #end for
3398        ri.pseudopotential = obj(
3399            species = np.array(species),
3400            pseudos = np.array(pps),
3401            )
3402    #end if
3403
3404    # incorporate system details, if provided
3405    if system is not None:
3406
3407        # add system details
3408        if copy_system:
3409            system = system.copy()
3410        #end if
3411        if use_folded:
3412            system = system.get_smallest()
3413        #end if
3414        system.check_folded_system()
3415        system.update_particles()
3416
3417        # set atomic species, positions, magnetic moments and mobility
3418        if 'atomic_coordinate_type' not in ri:
3419            ri.atomic_coordinate_type = 'Absolute'
3420        #end if
3421        if 'crds_units' not in ri:
3422            cu = default_units
3423
3424        else:
3425            cu = ri.crds_units.lower()
3426        #end if
3427        if cu=='angstrom':
3428            system.change_units('A')
3429        elif cu=='bohr':
3430            system.change_units('B')
3431        else:
3432            error('Invalid crds_units.\nExpected "Angstrom" or "Bohr".\nReceived: {}'.format(cu),loc)
3433        #end if
3434        rmg_length_units = rmg_units_map[cu]
3435        if 'crd_units' not in ri and 'atomic_coordinate_type' in ri and ri.atomic_coordinate_type=='Absolute':
3436            ri.crd_units = rmg_length_units
3437        #end if
3438        s = system.structure
3439        elem = np.array(s.elem)
3440        act = ri.atomic_coordinate_type.lower()
3441        if act=='absolute':
3442            pos = s.pos.copy()
3443        elif act=='cell relative':
3444            pos = s.pos_unit().copy()
3445        else:
3446            error('Invalid atomic_coordinate_type.\nExpected "Absolute" or "Cell Relative".\nReceived: {}'.format(cu),loc)
3447        #end if
3448        movable = None
3449        if s.frozen is not None:
3450            movable = ~s.is_frozen()
3451        #end if
3452        moments = None
3453        if s.mag is not None:
3454            moments = np.array(s.mag,dtype=float)
3455        #end if
3456        if movable is not None and moments is not None:
3457            ri.atoms = obj(
3458                format = 'movable_moment',
3459                atoms     = elem,
3460                positions = pos,
3461                movable   = movable,
3462                moments   = moments,
3463                )
3464        elif movable is not None:
3465            ri.atoms = obj(
3466                format = 'movable',
3467                atoms     = elem,
3468                positions = pos,
3469                movable   = movable,
3470                )
3471        else:
3472            ri.atoms = obj(
3473                format = 'basic',
3474                atoms     = elem,
3475                positions = pos,
3476                )
3477        #end if
3478
3479        # set lattice vectors
3480        if 'a_length' not in ri:
3481            ri.lattice_units  = rmg_length_units
3482            ri.lattice_vector = s.axes.copy()
3483        #end if
3484
3485        # set kpoints
3486        if len(s.kpoints)>0 and 'kpoint_mesh' not in ri:
3487            kpu = s.kpoints_unit()
3488            ri.kpoints = obj(
3489                kpoints = kpu.copy(),
3490                weights = s.kweights.copy(),
3491                )
3492            if 'kpoint_is_shift' in ri:
3493                del ri.kpoint_is_shift
3494            #end if
3495        #end if
3496
3497        # set wavefunction grid
3498        if wf_grid_spacing is not None:
3499            wf_grid = []
3500            for a in system.structure.axes:
3501                g = int(np.ceil(np.linalg.norm(a)/wf_grid_spacing))
3502                wf_grid.append(g)
3503            #end for
3504            ri.assign(wavefunction_grid=wf_grid)
3505        #end if
3506
3507        if spin_polarized is None and 'noncollinear' not in ri:
3508            spin_polarized = system.spin_polarized_orbitals()
3509        elif spin_polarized is None and 'noncollinear' in ri:
3510            if not ri.noncollinear:
3511                spin_polarized = system.spin_polarized_orbitals()
3512            #end if
3513        #end if
3514
3515        # set occupations
3516        has_states = False
3517        has_states |= 'states_count_and_occupation' in ri
3518        has_states |= 'states_count_and_occupation_up' in ri and 'states_count_and_occupation_down' in ri
3519        if not has_states and virtual_frac is not None:
3520            states_keys = [
3521                'states_count_and_occupation',
3522                'states_count_and_occupation_up',
3523                'states_count_and_occupation_down',
3524                ]
3525            for k in states_keys:
3526                if k in ri:
3527                    del ri[k]
3528                #end if
3529            #end for
3530            nup,ndn = system.particles.electron_counts()
3531            nvirt = int(np.ceil(virtual_frac*max(nup,ndn)))
3532            nptot = max(nup,ndn) + nvirt
3533            nup_virt = nptot-nup
3534            ndn_virt = nptot-ndn
3535            if nup==ndn and not spin_polarized:
3536                occ_up = '{} 2.0 {} 0.0'.format(nup,nup_virt)
3537                ri.states_count_and_occupation = occ_up
3538            else:
3539                occ_up = '{} 1.0 {} 0.0'.format(nup,nup_virt)
3540                occ_dn = '{} 1.0 {} 0.0'.format(ndn,ndn_virt)
3541                ri.states_count_and_occupation_spin_up   = occ_up
3542                ri.states_count_and_occupation_spin_down = occ_dn
3543            #end if
3544        #end if
3545
3546    #end if
3547
3548    if spin_polarized is not None and spin_polarized:
3549        if 'states_count_and_occupation_spin_up' not in ri:
3550            error('System is spin polarized, but occupations not provided for up and down spins.',loc)
3551        #end if
3552    #end if
3553
3554    return ri
3555#end def generate_any_rmg_input
3556