Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 10 additions & 10 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,22 @@ jobs:
build-linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.8
- uses: actions/checkout@v3
- name: Set up Python 3.12
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.12
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
- name: Install dependencies
shell: bash -l {0}
run: |
conda install python=3.8
conda install numpy
conda install python=3.12
conda install -c conda-forge gpy
conda install pytorch
conda install numpy
conda install -c conda-forge pytorch=2.1.2
conda install pandas
conda install -c conda-forge cclib
conda install -c conda-forge hyperopt
Expand All @@ -48,7 +48,7 @@ jobs:
matrix:
cfg:
- conda-env: docs-cf
python-version: 3.8
python-version: 3.12
label: Sphinx
runs-on: ubuntu-latest

Expand All @@ -59,13 +59,13 @@ jobs:
- uses: actions/checkout@v3

- name: Create Environment
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: test
environment-file: docs/requirements.yml
python-version: ${{ matrix.cfg.python-version }}
auto-activate-base: false
miniforge-variant: Mambaforge
miniforge-variant: Miniforge3
miniforge-version: latest
use-mamba: true
add-pip-as-python-dependency: true
Expand All @@ -74,4 +74,4 @@ jobs:
- name: Environment Information
run: |
mamba info
mamba list --show-channel-urls
mamba list
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ jobs:
uses: actions/checkout@v3

- name: Create Environment
uses: conda-incubator/setup-miniconda@v2
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: docs-env
environment-file: docs/requirements.yml
python-version: ${{ matrix.cfg.python-version }}
miniforge-variant: Mambaforge
miniforge-variant: Miniforge3
use-mamba: true
add-pip-as-python-dependency: true
channels: conda-forge
Expand Down
4 changes: 2 additions & 2 deletions docs/requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ channels:
- nodefaults
- conda-forge
dependencies:
- python=3.8
- python=3.12
- sphinx
- sphinx_rtd_theme
- sphinx-book-theme
Expand All @@ -13,11 +13,11 @@ dependencies:
- autodoc-pydantic

# PESLearn depends
- GPy >=1.9
- numpy
- pydantic >=0.30.1
- qcelemental >=0.9.0
- numpy >=1.7
- GPy >=1.9
- scikit-learn >=0.20
- pandas >=0.24
- hyperopt >=0.1.1
Expand Down
38 changes: 38 additions & 0 deletions peslearn/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,3 +180,41 @@ def cart1d_to_distances1d(vec):
distance_vector = distance_matrix[np.tril_indices(len(distance_matrix),-1)]
return distance_vector
"""

gradient_nn_convenience_function = """
# how to use 'gradient_compute()' function
# --------------------------------------
# grads = gradient_compute(cartesian_dataset_path)
# 'cartesian_dataset_path' is a path to a dataset with cartesian coordinates that will be used with model to predict gradients.
# Cartesian geometries should contain atomic symbol (e.g. H, C, Br, etc.) followed by XYZ cartesian coordinates each separated by spaces.
# The dataset may contain one or multiple geometries, if given multiple geometries it will return a list of multiple gradients
# The output of the 'gradient_compute()' function will be the negative derivative of the predicted energy from the model with respect to
# the cartesian coordinate of the provided geometry.
# i.e. ouput = -dE/dq, where output is the returned value from the 'gradient_compute()' function, E is the model predicted energy, and q are the cartesian coordinates
# Input coordinates need not be in standard order, they will however be transformed into standard order for the output.
# Standard order in PES-Learn lists most common atoms first with alphabetical tiebreakers.
# e.g. If the input provided for water lists the XYZ coordinates in order of O H1 H2, then the output gradient will be in the order H1 H2 O.
# The returned gradients will be in units of Hartree/distance where distance is either Bohr or Angstrom.
# The distance unit used to construct the model should be the same distance unit used to predict gradients.
# Outputs are of the form of a list of torch tensors, where each tensor is a predicted gradient in the order provided in the catesian dataset.
# Using this function for the first time creates a new file containing a function tailored to the given input molecule.

def gradient_compute(cart_dataset_path):
grad = []
# transform
sorted_atoms, geoms = geometry_transform_helper.load_cartesian_dataset(cart_dataset_path, no_energy=True)
for i in range(len(geoms)):
geoms[i] = geometry_transform_helper.remove_atom_labels(geoms[i])
if not os.path.exists('grad_func.py'):
geometry_transform_helper.write_grad_input(sorted_atoms)
from grad_func import gradient_prediction
for g in range(len(geoms)):
grad.append(gradient_prediction(nn, params, model, Xscaler, yscaler, geoms[g]))
return grad
"""






22 changes: 11 additions & 11 deletions peslearn/datagen/outputfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, output_path):
self.output_str = f.read()

def extract_energy_with_regex(self, energy_regex):
"""
r"""
Finds the energy value (a float) in an output file according to a user supplied
regular expression identifier.

Expand All @@ -34,15 +34,15 @@ def extract_energy_with_regex(self, energy_regex):
FINAL ELECTRONIC ENERGY (Eh): -2.3564983498

One can obtain this floating point number with the regex identifier:
\s*FINAL ELECTRONIC ENERGY \(Eh\):\s+(-\d+\.\d+)
r"\s*FINAL ELECTRONIC ENERGY \(Eh\):\s+(-\d+\.\d+)"

Checking ones regular expression is easy with online utilities such as pythex (see pythex.org)

Parameters
---------
energy_regex : str
A string containing the regex code for capturing an energy floating point number.
e.g. "\s*FINAL ELECTRONIC ENERGY \(Eh\):\s+(-\d+\.\d+)"
e.g. r"\s*FINAL ELECTRONIC ENERGY \(Eh\):\s+(-\d+\.\d+)"

Returns
-------
Expand Down Expand Up @@ -126,11 +126,11 @@ def extract_from_schema(self, driver):
"""
if driver == "energy":
energy = []
energy = re.findall("\s\'return_energy\'\:\s+(-\d+\.\d+)", self.output_str)
energy = re.findall(r"\s\'return_energy\'\:\s+(-\d+\.\d+)", self.output_str)
if energy:
return energy
else:
success = re.findall("\s\'success\'\:\s+(\S+)\}", self.output_str)
success = re.findall(r"\s\'success\'\:\s+(\S+)\}", self.output_str)
if success[0] == 'False':
energy = 'False'
return energy
Expand All @@ -140,7 +140,7 @@ def extract_from_schema(self, driver):
return energy

if driver == "gradient":
gradient = re.findall("\s\'return_gradient\'\:\s+array\(([\s\S]*?)\)\,", self.output_str)
gradient = re.findall(r"\s\'return_gradient\'\:\s+array\(([\s\S]*?)\)\,", self.output_str)
if gradient:
import ast
gradient = re.sub(r'\s+', "", str(gradient))
Expand All @@ -150,7 +150,7 @@ def extract_from_schema(self, driver):
gradient = np.asarray(ast.literal_eval(gradient)).astype(np.float64)
return gradient
else:
success = re.findall("\s\'success\'\:\s+(\S+)\}", self.output_str)
success = re.findall(r"\s\'success\'\:\s+(\S+)\}", self.output_str)
if success[0] == 'False':
gradient = 'False'
return gradient
Expand All @@ -160,7 +160,7 @@ def extract_from_schema(self, driver):


if driver == "hessian":
hessian = re.findall("\s\'return_hessian\'\:\s+array\(([\s\S]*?)\)\,", self.output_str)
hessian = re.findall(r"\s\'return_hessian\'\:\s+array\(([\s\S]*?)\)\,", self.output_str)
if hessian:
import ast
hessian = re.sub(r'\s+', "", str(hessian))
Expand All @@ -170,7 +170,7 @@ def extract_from_schema(self, driver):
hessian = np.asarray(ast.literal_eval(hessian)).astype(np.float64)
return hessian
else:
success = re.findall("\s\'success\'\:\s+(\S+)\}", self.output_str)
success = re.findall(r"\s\'success\'\:\s+(\S+)\}", self.output_str)
if success[0] == 'False':
hessian = 'False'
return hessian
Expand All @@ -185,7 +185,7 @@ def extract_from_schema(self, driver):
return properties

def extract_cartesian_gradient_with_regex(self, header, footer, grad_line_regex):
"""
r"""
Extracts cartesian gradients according to user supplied regular expressions.
A bit more tedious to use than the energy regex extractor as the size of the regular expressions may be quite long.
Requires that the electronic structure theory code prints the cartesian gradient in a logical way.
Expand Down Expand Up @@ -214,7 +214,7 @@ def extract_cartesian_gradient_with_regex(self, header, footer, grad_line_regex)
Atom 1 Cl 0.00000 0.23410 0.32398
Atom 2 H 0.02101 0.09233 0.01342
Atom 3 N 0.01531 0.04813 0.06118
A valid argument for grad_line_regex would be "Atom\s+\d+\s+[A-Z,a-z]+\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)"
A valid argument for grad_line_regex would be r"Atom\s+\d+\s+[A-Z,a-z]+\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)\s+(-?\d+\.\d+)"
This can easily be tested with online utilities such as pythex (see pythex.org)
Returns
-------
Expand Down
12 changes: 6 additions & 6 deletions peslearn/input_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class InputProcessor(object):
"""
def __init__(self, input_string):
# Remove all comments denoted by '#'
self.full_string = re.sub('\s*#.+', '', input_string)
self.full_string = re.sub(r'\s*#.+', '', input_string)
if re.search(regex.intcoords_regex, self.full_string):
self.zmat_string = re.findall(regex.intcoords_regex, self.full_string)[0]
self.intcos_ranges = None
Expand Down Expand Up @@ -81,7 +81,7 @@ def get_keywords(self):
}

for k in string_keywords:
match = re.search(k+"\s*=\s*(.+)", self.full_string)
match = re.search(k + r"\s*=\s*(.+)", self.full_string)
# if the keyword is mentioned
if match:
value = str(match.group(1))
Expand All @@ -90,7 +90,7 @@ def get_keywords(self):
if k not in regex_keywords:
value = value.lower().strip()
# if keyword is raw text, add quotes so it is a string
if re.match("[a-z\_]+", value):
if re.match(r"[a-z\_]+", value):
if (r"'" or r'"') not in value:
value = "".join((r'"',value,r'"',))
try:
Expand All @@ -114,19 +114,19 @@ def extract_intcos_ranges(self):
# for every geometry label look for its range identifer, e.g. R1 = [0.5, 1.2, 25]
for label in geomlabels:
# check to make sure parameter isn't defined more than once
if len(re.findall("\W" + label+"\s*=\s*", self.full_string)) > 1:
if len(re.findall(r"\W" + label + r"\s*=\s*", self.full_string)) > 1:
raise Exception("Parameter {} defined more than once.".format(label))

# if geom parameter has a geometry range, save it
match = re.search(label+"\s*=\s*(\[.+\])", self.full_string)
match = re.search(label + r"\s*=\s*(\[.+\])", self.full_string)
if match:
try:
ranges[label] = ast.literal_eval(match.group(1))
except:
raise Exception("Something wrong with definition of parameter {} in input. Should be of the form [start, stop, # of points] or a fixed value".format(label))
# if it has a fixed value, save it
else:
match = re.search(label+"\s*=\s*(-?\d+\.?\d*)", self.full_string)
match = re.search(label + r"\s*=\s*(-?\d+\.?\d*)", self.full_string)
if not match:
raise Exception("\nDefinition of parameter {} not found in geometry input. \
\nThe definition is either missing or improperly formatted".format(label))
Expand Down
1 change: 1 addition & 0 deletions peslearn/lib/A2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2B/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2B2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2B2C/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2B2C2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2B2C2D/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2B2C2D2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2B2C2DE/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2B2CD/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2B2CDE/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2B2CDEF/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2BC/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2BCD/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2BCDE/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2BCDEF/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A2BCDEFG/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3B/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3B2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3B2C/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3B2C2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3B2C2D/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3B2CD/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3B2CDE/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3B3/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3B3C/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3B3CD/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3BC/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3BCD/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3BCDE/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A3BCDEF/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A4/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A4B/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A4B2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A4B2C/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A4B2CD/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A4B3C/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
1 change: 1 addition & 0 deletions peslearn/lib/A4BC/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import output
File renamed without changes.
Loading
Loading