Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input parsing cleaning and PhysConsts from QCelemental #404

Merged
merged 75 commits into from
Apr 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
7c3b8e3
Added predicate for ensuring positive spin multiplicities
Mar 24, 2022
4df67d2
Moved the molecule validation out of the api file, to make the struct…
Mar 24, 2022
b9d3b1d
Simplified write_molecule function
Mar 24, 2022
83bad78
Removed method for writing to program syntax. might as well do this i…
Mar 24, 2022
9eef63c
Removed import of weird package that was sneaked in somehow
Mar 24, 2022
73902ed
Cleanup and doc
Mar 25, 2022
18843e7
Not use walrus operator to avoid having to change python version requ…
Mar 25, 2022
1605865
fix comment typo
Brakjen Mar 25, 2022
a038d83
Removed unnecessary todo
Mar 25, 2022
20a4217
Removed __init__ file in input parsing plumbing
Mar 25, 2022
7960907
Cleaned up the imports, moved constants to separate file temporarily to
Mar 25, 2022
d073311
Converted test input to json
Mar 28, 2022
005c09a
Removed duplicated cavity sphere in ref input and reran test. The tes…
Mar 28, 2022
96a0527
Added short docstring
Mar 28, 2022
52c019e
Sketched the handling of physical constants to use qcelemental on the…
Mar 30, 2022
22333a9
Write constants to program.json
Mar 31, 2022
a2c1fa0
Singleton class providing access to the constants.
Mar 31, 2022
d4d0f98
clang format
Mar 31, 2022
779b3c1
clang format
Mar 31, 2022
83c35cb
clanga format
Mar 31, 2022
f668dc3
Added default constants to constructor. will be accessed if no data h…
Apr 1, 2022
09fe423
Added qcelemental as python dep
Apr 1, 2022
fcb4c35
Now only a subset of the constants relevant for MRChem are added to t…
Apr 4, 2022
6dda95e
Added qcelemental to let tests run via github actions pass.
Apr 4, 2022
9b77d4c
Fixed bug in the case of constants name. all constants passed to cpp …
Apr 4, 2022
fa39973
Added qcelemental to make codecoverage pass
Apr 4, 2022
2fde3bf
Minor style fixes.
Apr 4, 2022
475d464
Removed unused import.
Apr 4, 2022
7528d8e
Comment docs
Apr 4, 2022
505bc78
Redesigned MRChemConstants. No longer inherits from qcelemental, but …
Apr 5, 2022
4858ecd
Fixed indendation
Apr 5, 2022
374c329
Added qcelemental to dev packages
Apr 5, 2022
6607872
Updated singleton design, and the calls for fetching constants.
Apr 5, 2022
4820d7e
Updated call to MRChemConstants
Apr 5, 2022
ef56699
Fix symbols not found error during linking.
Apr 6, 2022
05ce3a4
Remove explicitly defined constants. will fix unit tests later
Apr 6, 2022
8f88517
clang format
Apr 6, 2022
efcdfa8
Script that can update the constants section in template.yml, execute…
Apr 6, 2022
d0b5d1d
Added description to CLI interface
Apr 6, 2022
ee0542e
Update to match name for light speed constant
Apr 6, 2022
569f9a9
Minor style changes
Apr 6, 2022
76a6c5c
Small bug fixes
Apr 6, 2022
9a688ba
Now fetch constants from user_dict
Apr 6, 2022
9479eca
Added instructions for updating constants and the input parser with t…
Apr 6, 2022
51958c7
Updated template and input parser to allow the user to overwrite cons…
Apr 6, 2022
9e5e916
Updated README
Apr 6, 2022
f3c81da
Added dryrun option to CLI
Apr 6, 2022
a509ce4
Store constants explicitly in cpp to make unit tests pass.
Apr 6, 2022
c5dce35
Remove qcelemental dependency from input parsing.
Apr 6, 2022
df73d7a
Clarify instructions on updating the input parser
Brakjen Apr 7, 2022
1ead17b
Updated the way constants are defined. Removed unused constants. Adde…
Apr 7, 2022
cc8b2dd
Updated constant docstrings plus some minor cleanups
Apr 7, 2022
ea3e411
Removed sqrt(pi) as a separate constant
Apr 7, 2022
0298536
Removed light_speed keyword from ZORA input section. This is taken ca…
Apr 7, 2022
3127872
Removed light_speed keyword from ZORA input section. This is taken ca…
Apr 7, 2022
e67d732
Added a print function to PhysicalConstants. Prints at printlevel 0.
Apr 7, 2022
19bec5d
Bug fixes related to the light speed keyword being moved from ZORA to…
Apr 7, 2022
b70a07a
Removed pi from mrchem constants. Now mrcpp::pi is used for all calls…
Apr 7, 2022
ecc035a
Added constants section to input schema
Apr 8, 2022
acf8960
Made constants being printed at printlevel 1 and above
Apr 8, 2022
20f0307
Added keyword to printer so that the user can choose when to print th…
Apr 11, 2022
13ef30f
Merge branch 'master' into molecule-class-cleanup-input-parser
Brakjen Apr 11, 2022
3142afe
Fix error from conflic resolution
Apr 11, 2022
f800d3f
Merge branch 'master' into molecule-class-cleanup-input-parser
stigrj Apr 12, 2022
c7bb479
Minor cleanups
Apr 21, 2022
52ff645
Increased distance to colon to allow for printing longer strings
Apr 21, 2022
1cf402f
Ensure the indentation scheme in the input template.
Apr 25, 2022
484da12
Added json print helper method to print_utils. Use this to print phys…
Apr 25, 2022
69158fe
Undo modification to print widths.
Apr 25, 2022
0fe4162
Removed unused parameters.
Apr 25, 2022
6c7e724
Added ruamel.yaml to dev packages
Apr 25, 2022
c0da948
Updated json printer to newest version.
Apr 26, 2022
e31df4f
Fix colon shift
Apr 27, 2022
8ae0fc7
Add cavity input section only when used
Apr 27, 2022
d135280
Update input schema with cavity changes
stigrj Apr 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ name = "pypi"
[packages]

[dev-packages]
qcelemental = "<= 0.24.0"
Pygments = "*"
recommonmark = "*"
Sphinx = ">=2.0"
Expand All @@ -15,3 +16,4 @@ breathe = "*"
pyyaml = "*"
yapf = "*"
parselglossy = ">=0.7"
ruamel.yaml = ">=0.17.21"
28 changes: 21 additions & 7 deletions doc/users/schema_input.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@
"xyz": array[float] # Nuclear Cartesian coordinate
}
],
"cavity_coords": array[ # Array of solvation cavities
{ # (one entry per sphere)
"center": array[float], # Cartesian coordinate of sphere center
"radius": float # Radius of cavity sphere
}
],
"cavity_width": float # Width of cavity boundary
"cavity": {
"spheres": array[ # Array of cavity spheres
{ # (one entry per sphere)
"center": array[float], # Cartesian coordinate of sphere center
"radius": float # Radius of cavity sphere
}
],
"width": float # Width of cavity boundary
}
},
"mpi": { # Section for MPI specification
"bank_size": int, # Number of MPI ranks in memory bank
Expand Down Expand Up @@ -294,5 +296,17 @@
}
}
}
},
"constants": { # Physical constants used throughout MRChem
"angstrom2bohrs": float, # Conversion factor from Angstrom to Bohr
"dipmom_au2debye": float, # Conversion factor from atomic units to Debye
"electron_g_factor": float, # Electron g factor in atomic units
"fine_structure_constant": float, # Fine-structure constant in atomic units
"hartree2ev": float, # Conversion factor from Hartree to eV
"hartree2kcalmol": float, # Conversion factor from Hartree to kcal/mol
"hartree2kjmol": float, # Conversion factor from Hartree to kJ/mol
"hartree2simagnetizability": float, # Conversion factor from Hartree to J T^-2
"hartree2wavenumbers": float, # Conversion factor from Hartree to cm^-1
"light_speed": float # Speed of light in vacuo in atomic units
}
}
80 changes: 73 additions & 7 deletions doc/users/user_ref.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ User input reference
**Predicates**
- ``50 < value < 100``

:print_constants: Print table of physical constants used by MRChem.

**Type** ``bool``

**Default** ``False``

:Plotter: Give details regarding the density and orbital plots. Three types of plots are available, line, surface and cube, and the plotting ranges are defined by three vectors (A, B and C) and an origin (O): ``line``: plots on line spanned by A, starting from O. ``surf``: plots on surface spanned by A and B, starting from O. ``cube``: plots on volume spanned by A, B and C, starting from O.

:red:`Keywords`
Expand Down Expand Up @@ -285,6 +291,9 @@ User input reference

**Default** ``1``

**Predicates**
- ``value > 0``

:translate: Translate coordinates such that center of mass coincides with the global gauge origin.

**Type** ``bool``
Expand Down Expand Up @@ -323,12 +332,6 @@ User input reference
:ZORA: Define required parameters for the ZORA Hamiltonian.

:red:`Keywords`
:light_speed: Adjust speed of light.

**Type** ``float``

**Default** ``-1.0``

:include_nuclear: Include the nuclear potential ``V_nuc`` in the ZORA potential.

**Type** ``bool``
Expand Down Expand Up @@ -863,4 +866,67 @@ User input reference

**Predicates**
- ``value.lower() in ['exponential']``


:Constants: Physical and mathematical constants used by MRChem

:red:`Keywords`
:hartree2simagnetizability: | Conversion factor for magnetizability from atomic units to SI units (unit: J T^-2). Affected code: Printed value of the magnetizability property.

**Type** ``float``

**Default** ``78.9451185``

:light_speed: | Speed of light in atomic units (unit: au). Affected code: Relativistic Hamiltonians (ZORA, etc.)

**Type** ``float``

**Default** ``137.035999084``

:angstrom2bohrs: | Conversion factor for Cartesian coordinates from Angstrom to Bohr (unit: Å^-1). Affected code: Parsing of input coordinates, printed coordinates

**Type** ``float``

**Default** ``1.8897261246257702``

:hartree2kjmol: | Conversion factor from Hartree to kJ/mol (unit: kJ mol^-1). Affected code: Printed value of energies.

**Type** ``float``

**Default** ``2625.4996394798254``

:hartree2kcalmol: | Conversion factor from Hartree to kcal/mol (unit: kcal mol^-1). Affected code: Printed value of energies.

**Type** ``float``

**Default** ``627.5094740630558``

:hartree2ev: | Conversion factor from Hartree to eV (unit: ev). Affected code: Printed value of energies.

**Type** ``float``

**Default** ``27.211386245988``

:hartree2wavenumbers: | Conversion factor from Hartree to wavenumbers (unit: cm^-1). Affected code: Printed value of frequencies.

**Type** ``float``

**Default** ``219474.6313632``

:fine_structure_constant: | Fine-structure constant in atomic units (unit: au). Affected code: Certain magnetic interaction operators.

**Type** ``float``

**Default** ``0.0072973525693``

:electron_g_factor: | Electron g factor in atomic units (unit: au). Affected code: Certain magnetic interaction operators.

**Type** ``float``

**Default** ``-2.00231930436256``

:dipmom_au2debye: | Conversion factor for dipoles from atomic units to Debye (unit: ?). Affected code: Printed value of dipole moments.

**Type** ``float``

**Default** ``2.5417464739297717``

49 changes: 42 additions & 7 deletions python/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,48 @@
# How to update the input parser
# How to update the input parser...

Run:
## ...when you have updated the `Constants` input section
The `Constants` section require a bit of special treatment, because the constants are derived from NIST data via an interface
to `qcelemental`.
All constants should be defined in the class `MRChemPhysConstants` located in `python/mrchem/physical_constants.py`.
The utility script `python/mrchem/update_input_parser.py` will automatically replace the current `Constants`
section in `python/template.yml` with a new one generated by instantiating `MRChemPhysConstants` and
reading the subset of constants defined therein.

``` bash
To run the script:

```bash
$ cd python/mrchem
$ python update_input_parser.py
```

This does three things:

1. Update `template.yml` with the new `Constants` section
2. Run `parselglossy` to update the input parser
3. Copy the user reference file to `doc/users/user_ref.rst`

Each of these steps can be deactivated by appropriate flags. For help on running the script, run

```bash
$ cd python
$ parselglossy generate --template template.yml --docfile user_ref.rst --doc-header="User input reference" --target="mrchem/input_parser"
$ python update_input_parser.py -h
```
Remember to also update the documentation:

``` bash
cp python/mrchem/input_parser/docs/user_ref.rst doc/users/user_ref.rst
## ...when you have updated any other input section
If the `Constants` input section is unchanged, you can update the input parser by performing steps 2 and 3 above.
The utility script can also do this, by specifying the flag `--skip-template`:

```bash
$ cd python
$ python update_input_parser --skip-template
```

This will perform steps 2-3, updating the input parser and the user reference.

You can also perform these steps manually without using the utility script:

```bash
$ cd python
$ parselglossy generate --template template.yml --docfile user_ref.rst --doc-header="User input reference" --target="mrchem/input_parser"
$ cp mrchem/input_parser/docs/user_ref.rst ../doc/users/user_ref.rst
```
27 changes: 15 additions & 12 deletions python/mrchem/CUBEparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,20 @@
# For information on the complete list of contributors to MRChem, see:
# <https://mrchem.readthedocs.io/>
#
from .input_parser.plumbing import pyparsing as pp

import os
from json import dump

BOHR_2_METER = 5.29177210903e-11
"""Conversion from atomic units of length (Bohr) to meter (CODATA 2018)"""
ANGSTROM_2_BOHR = 1e-10 / BOHR_2_METER
#ANGSTROM_2_BOHR = 1.889725989
"""Conversion factor from Angstrom to Bohr"""
from .input_parser.plumbing import pyparsing as pp

global pc


def write_cube_dict(user_dict):
file_dict = user_dict['Files']
world_unit = user_dict['world_unit']
pc = user_dict['Constants']

def write_cube_dict(file_dict, world_unit):
all_path_list = []
all_path_list.append(sort_paths(file_dict["guess_cube_p"]))
all_path_list.append(sort_paths(file_dict["guess_cube_a"]))
Expand Down Expand Up @@ -175,7 +178,7 @@ def count(s, l, t):

# get cube origin data
N_atoms = parsed_cube["NATOMS"]
origin = parsed_cube["ORIGIN"] if (world_unit == "bohr") else [p*ANGSTROM_2_BOHR for p in parsed_cube["ORIGIN"]]
origin = parsed_cube["ORIGIN"] if (world_unit == "bohr") else [p * pc['angstrom2bohrs'] for p in parsed_cube["ORIGIN"]]

# Set the amount of values depending on if the DSET_IDs were present or not
if (len(parsed_cube["DSET_IDS"]) != 0):
Expand All @@ -200,9 +203,9 @@ def count(s, l, t):
if (world_unit == "bohr"):
Voxel_axes = [parsed_cube["XAXIS"]["VECTOR"], parsed_cube["YAXIS"]["VECTOR"], parsed_cube["ZAXIS"]["VECTOR"]]
else:
X_voxel = [p*ANGSTROM_2_BOHR for p in parsed_cube["XAXIS"]["VECTOR"]]
Y_voxel = [p*ANGSTROM_2_BOHR for p in parsed_cube["YAXIS"]["VECTOR"]]
Z_voxel = [p*ANGSTROM_2_BOHR for p in parsed_cube["ZAXIS"]["VECTOR"]]
X_voxel = [p * pc['angstrom2bohrs'] for p in parsed_cube["XAXIS"]["VECTOR"]]
Y_voxel = [p * pc['angstrom2bohrs'] for p in parsed_cube["YAXIS"]["VECTOR"]]
Z_voxel = [p * pc['angstrom2bohrs'] for p in parsed_cube["ZAXIS"]["VECTOR"]]
Voxel_axes = [X_voxel, Y_voxel, Z_voxel]

# get the atom coordinates
Expand All @@ -211,7 +214,7 @@ def count(s, l, t):

Z_n = [atom["ATOMIC_NUMBER"] for atom in parsed_cube["GEOM"]]
atom_charges = [atom["CHARGE"] for atom in parsed_cube["GEOM"]]
atom_coords = [atom["POSITION"] if (world_unit == "bohr") else [p*ANGSTROM_2_BOHR for p in atom["POSITION"]] for atom in parsed_cube["GEOM"]]
atom_coords = [atom["POSITION"] if (world_unit == "bohr") else [p * pc['angstrom2bohrs'] for p in atom["POSITION"]] for atom in parsed_cube["GEOM"]]

# construct the CUBE vector. Indexing is CUBE_vector[MO_ID][i*N_vals[1]*N_vals[2] + j*N_vals[2] + k] where i, j and k correspond to steps in the X, Y and Z voxel axes directions respectively.
CUBE_vector = []
Expand Down
Loading