Skip to content

Commit

Permalink
Merge pull request #135 from SCM-NV/DavidOrmrodMorley/sync-fix2024-20…
Browse files Browse the repository at this point in the history
…24-08-20

Final manual sync from fix2024 in the amshome repo.
  • Loading branch information
robertrueger authored Aug 26, 2024
2 parents 5c7d87a + 89146f2 commit 8976c77
Show file tree
Hide file tree
Showing 27 changed files with 231 additions and 76 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[flake8]
exclude=doc, examples
per-file-ignores = __init__.py:F401, setup.py:F821
select=F
137 changes: 137 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: CI

on:
# Run on creating or updating a PR
pull_request:
types: [opened, synchronize, reopened]

# And pushing to the trunk or fix branches
push:
branches:
- trunk
- 'fix*'

# And pushing new version tags e.g. 2024.103
tags:
- '20[0-9]{2}\.[0-9]{3}'

jobs:

unit-test:
# Run on ubuntu, mac and windows for python 3.8 (in AMS python stack) up to 3.11
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Move Repo To SCM Namespace and Set PYTHONPATH
if: runner.os != 'Windows'
run: |
mkdir -p scm/plams
find . -mindepth 1 -maxdepth 1 -not -name 'scm' -not -name '.*' -exec mv {} scm/plams/ \;
echo "PYTHONPATH=$(pwd):$PYTHONPATH" >> $GITHUB_ENV
- name: Move Repo To SCM Namespace and Set PYTHONPATH (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
New-Item -Path scm\plams -ItemType Directory -Force
Get-ChildItem -Directory | Where-Object { $_.Name -ne 'scm' } | ForEach-Object {
Move-Item -Path $_.FullName -Destination scm\plams
}
Get-ChildItem -File | ForEach-Object {
Move-Item -Path $_.FullName -Destination scm\plams
}
echo "PYTHONPATH=$(pwd);$env:PYTHONPATH" >> $env:GITHUB_ENV
- name: Set Up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
working-directory: scm/plams
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest
pip install coverage
- name: Run Unit Tests
working-directory: scm/plams
run: |
pwd
coverage run -m pytest unit_tests
# ToDo: Bump the fail-under threshold over time until acceptable level is reached
- name: Evaluate Coverage
working-directory: scm/plams
run: coverage report --omit="unit_tests/*" -i --fail-under=25


lint:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set Up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install black
pip install "black[jupyter]"
pip install flake8
- name: Run Black
run: |
black --check -t py38 -l 120 .
- name: Run Flake8
run: |
flake8 --color never --count --config .flake8 .
build-docs:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Move Repo To SCM Namespace and Set PYTHONPATH
run: |
mkdir -p scm/plams
find . -mindepth 1 -maxdepth 1 -not -name 'scm' -not -name '.*' -exec mv {} scm/plams/ \;
echo "PYTHONPATH=$(pwd):$PYTHONPATH" >> $GITHUB_ENV
- name: Set Up Python
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Install Dependencies
working-directory: scm/plams
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
cd doc
pip install -r requirements.txt
# Turn on the -W flag when building once warnings to external links have been resolved
# ToDo: add a warning allowlist to check the warnings logged via -w
- name: Build Sphinx Docs
working-directory: scm/plams/doc
run: |
python build_plams_doc
39 changes: 21 additions & 18 deletions doc/build_plams_doc
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,48 @@ import sys
from os.path import join as opj

command = ""
#Try to locate sphinx-build executable
if 'AMSBIN' in os.environ:
command = opj(os.path.expandvars('$AMSBIN'), 'python3.5', 'bin', 'sphinx-build')
# Try to locate sphinx-build executable
if "AMSBIN" in os.environ:
command = opj(os.path.expandvars("$AMSBIN"), "python3.8", "bin", "sphinx-build")
if not os.path.exists(command):
# This might be a windows machine
command = opj(os.path.expandvars('$AMSBIN'), 'python3.5', 'Scripts', 'sphinx-build.exe')
command = opj(os.path.expandvars("$AMSBIN"), "python3.8", "Scripts", "sphinx-build.exe")
if os.path.exists(command):
# starting sphinx-build on windows is tricky...
command = ['sh', opj(os.path.expandvars('$AMSBIN'), 'amspython'), '-m', 'sphinx']
command = ["sh", opj(os.path.expandvars("$AMSBIN"), "amspython"), "-m", "sphinx"]
else:
print('Warning: AMSBIN found in environment, but failed to locate sphinx-build')
print("Warning: AMSBIN found in environment, but failed to locate sphinx-build")
command = ""
if command == "":
null = open(os.devnull, 'wb')
null = open(os.devnull, "wb")
try:
subprocess.call(['sphinx-build','--version'], stdout=null, stderr=null)
command = 'sphinx-build'
subprocess.call(["sphinx-build", "--version"], stdout=null, stderr=null)
command = "sphinx-build"
except OSError:
try:
subprocess.call(['sphinx-build2','--version'], stdout=null, stderr=null)
command = 'sphinx-build2'
subprocess.call(["sphinx-build2", "--version"], stdout=null, stderr=null)
command = "sphinx-build2"
except OSError:
print('Error: Sphinx executable not found!')
print("Error: Sphinx executable not found!")
null.close()
sys.exit(0)
null.close()

location = os.path.dirname(os.path.realpath(__file__))
#Source of documentation should be located in "source" subfolder next to this script
source = opj(location, 'source')
# Source of documentation should be located in "source" subfolder next to this script
source = opj(location, "source")

#Target can be given as command line argument, if not the "build" subfolder is used
# Target can be given as command line argument, if not the "build" subfolder is used
if len(sys.argv) > 1:
target = sys.argv[1]
else:
target = opj(location, 'build')
target = opj(location, "build")

warning_file = "build_plams_doc_warn_errors.txt"
if isinstance(command, list):
# on windows command is a list of multiple items
subprocess.call(command + [source, target])
return_code = subprocess.call(command + [source, target, "-w", warning_file])
else:
subprocess.call([command, source, target])
return_code = subprocess.call([command, source, target, "-w", warning_file])

sys.exit(return_code)
4 changes: 4 additions & 0 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sphinx
sphinx_copybutton
sphinx_tabs
ipython
4 changes: 2 additions & 2 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def modify_signature(app, what, name, obj, options, signature, return_annotation

def setup(app):
if not tags.has("scm_theme"):
app.add_stylesheet("boxes.css")
app.add_css_file("boxes.css")
app.add_directive("warning", Danger)
app.add_directive("technical", Important)
app.connect("autodoc-process-signature", modify_signature)
Expand All @@ -41,7 +41,7 @@ def setup(app):

else:

extensions = []
extensions = ["sphinx_tabs.tabs"]

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]
Expand Down
5 changes: 1 addition & 4 deletions examples/QE_AMS_AFM_HubbardU.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ def get_settings() -> Settings:
smearing="gaussian",
degauss=0.02,
nspin=2,
starting_magnetization=[
Settings(Label="Fe1", Value=1.0),
Settings(Label="Fe2", Value=-1.0)
],
starting_magnetization=[Settings(Label="Fe1", Value=1.0), Settings(Label="Fe2", Value=-1.0)],
)

# You may also just use the normal PLAMS Settings dot notation
Expand Down
18 changes: 9 additions & 9 deletions examples/ReactionEnergyBenchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@

# summary.txt will contain a table similar to the below
##Method HC7_1 HC7_2 HC7_3 HC7_4 HC7_5 HC7_6 HC7_7 ISOL6_1 ISOL6_2 ISOL6_3 ISOL6_4 ISOL6_5 (kcal/mol)
#Truhlar_ref 14.34 25.02 1.90 9.81 14.84 193.99 127.22 9.77 21.76 6.82 33.52 5.30
#Smith_wB97X_ref 28.77 41.09 1.75 6.26 9.30 238.83 157.65 9.32 20.80 1.03 26.43 0.40
#ANI-1ccx 15.8 30.7 -0.2 7.7 11.7 196.5 127.9 9.2 21.5 3.8 35.4 6.9
#ANI-2x 42.4 48.1 -1.9 5.4 8.0 238.4 156.9 7.9 20.8 -1.5 26.7 0.5
#DFTB 7.1 19.0 0.2 3.6 5.4 223.5 150.8 11.7 22.6 7.9 35.2 8.6
#ReaxFF 34.3 23.0 13.4 2.6 5.5 289.2 168.3 -9.2 24.2 70.7 30.9 89.3
#ADF 20.8 31.4 -1.9 6.7 9.9 214.5 139.7 9.5 20.5 4.7 31.0 4.8
#MP2 20.5 27.1 5.4 9.9 15.0 214.8 141.3 11.0 24.6 8.4 36.8 6.2
#BAND 19.2 30.2 -2.7 7.3 11.0 218.5 141.3 9.9 18.5 5.3 31.7 4.7
# Truhlar_ref 14.34 25.02 1.90 9.81 14.84 193.99 127.22 9.77 21.76 6.82 33.52 5.30
# Smith_wB97X_ref 28.77 41.09 1.75 6.26 9.30 238.83 157.65 9.32 20.80 1.03 26.43 0.40
# ANI-1ccx 15.8 30.7 -0.2 7.7 11.7 196.5 127.9 9.2 21.5 3.8 35.4 6.9
# ANI-2x 42.4 48.1 -1.9 5.4 8.0 238.4 156.9 7.9 20.8 -1.5 26.7 0.5
# DFTB 7.1 19.0 0.2 3.6 5.4 223.5 150.8 11.7 22.6 7.9 35.2 8.6
# ReaxFF 34.3 23.0 13.4 2.6 5.5 289.2 168.3 -9.2 24.2 70.7 30.9 89.3
# ADF 20.8 31.4 -1.9 6.7 9.9 214.5 139.7 9.5 20.5 4.7 31.0 4.8
# MP2 20.5 27.1 5.4 9.9 15.0 214.8 141.3 11.0 24.6 8.4 36.8 6.2
# BAND 19.2 30.2 -2.7 7.3 11.0 218.5 141.3 9.9 18.5 5.3 31.7 4.7
2 changes: 1 addition & 1 deletion examples/ams_crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def solubility():
s.input.compound[0].frac1 = 1.0

s.input.compound[1]._h = solute_coskf
s.input.compound[1].nring = 6 # number of ring atoms benzene
s.input.compound[1].nring = 6 # number of ring atoms benzene
s.input.compound[1].meltingpoint = solute_properties["meltingpoint"]
s.input.compound[1].hfusion = solute_properties["hfusion"] * Units.convert(
1.0, "kJ/mol", "kcal/mol"
Expand Down
12 changes: 4 additions & 8 deletions interfaces/adfsuite/ams.py
Original file line number Diff line number Diff line change
Expand Up @@ -1230,9 +1230,7 @@ def tolist(x):
else:
return [x]

conversion_ratio = Units.conversion_ratio("au", unit)
sec = "History"
nEntries = self.readrkf(sec, "nEntries")

items = [
"IRCDirection",
Expand All @@ -1249,7 +1247,6 @@ def tolist(x):
forw = {}
back = {}
reformed = {}
converged_mask = None
forw_mask = None
back_mask = None
converged = self.get_history_property("Converged", history_section=sec)
Expand All @@ -1274,7 +1271,6 @@ def tolist(x):
back_mask = [x != 1 for x in d[k]]
d[k] = ["Forward" if x == 1 else "Backward" if x == 2 else x for x in d[k]]

n = len(d[k])
forw[k] = list(compress(d[k], forw_mask))
back[k] = list(compress(d[k], back_mask))
back[k].reverse()
Expand Down Expand Up @@ -2275,10 +2271,10 @@ def get_runscript(self):
ret += f'export SCM_SRUN_OPTIONS="$SCM_SRUN_OPTIONS -N {nnode}"\n'
if _has_scm_pisa and isinstance(self.settings.input, DriverBlock):
if self.settings.input.Engine.name == "QuantumESPRESSO":
ret += f"export SCM_DISABLE_MPI=1\n"
ret += "export SCM_DISABLE_MPI=1\n"
else:
if "QuantumEspresso" in self.settings.input:
ret += f"export SCM_DISABLE_MPI=1\n"
ret += "export SCM_DISABLE_MPI=1\n"
if "preamble_lines" in self.settings.runscript:
for line in self.settings.runscript.preamble_lines:
ret += f"{line}\n"
Expand Down Expand Up @@ -2509,7 +2505,7 @@ def _serialize_molecule(self):

def serialize_to_settings(name, mol):
if isinstance(mol, Molecule):
sett = serialize_molecule_to_settings(mol)
sett = serialize_molecule_to_settings(mol, name)
elif _has_scm_unichemsys and isinstance(mol, ChemicalSystem):
sett = serialize_unichemsys_to_settings(mol)

Expand All @@ -2524,7 +2520,7 @@ def serialize_unichemsys_to_settings(mol):
sett = InputParserFacade().to_settings(AMSJob._command, str(mol))
return sett.ams.system[0]

def serialize_molecule_to_settings(mol):
def serialize_molecule_to_settings(mol, name: str = None):
sett = Settings()

if len(mol.lattice) in [1, 2] and mol.align_lattice():
Expand Down
12 changes: 6 additions & 6 deletions interfaces/adfsuite/crs.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def get_results(self, section=None) -> dict:
raise ValueError("Results object is missing or incomplete.")

# first get the two ranges for the indices
ncomp = self.readkf(section, "ncomp")
ncomp = self.readkf(section, "ncomp")
nitems = self.readkf(section, "nitems")
try:
nstruct = self.readkf(section, "nstruct")
Expand Down Expand Up @@ -142,17 +142,17 @@ def get_multispecies_dist(self):
This function returns multispecies distribution for each (compound,structure) pair. The format is a list
with indices corresponding to compound indices. Each item in the list is a dictionary with a structure name : list pair, where the structure name corresponds to a structure the compound can be exist as and the list is the distribution of that compound in that structure over the number of points (mole fractions, temperatures, pressures).
"""
res = self.get_results()
res = self.get_results()
property_name = res["property"].rstrip()

if(property_name=="LOGP"):
if property_name == "LOGP":
nPhase = 2
else:
nPhase = 1

ncomp = self.readkf(self.section, "ncomp")
struct_names = res["struct names"]
num_points = self.readkf(self.section, "nitems")
ncomp = self.readkf(self.section, "ncomp")
struct_names = res["struct names"]
num_points = self.readkf(self.section, "nitems")
valid_structs = [[] for _ in range(ncomp)]
comp_dist = res["comp distribution"].flatten()
for i in range(len(struct_names)):
Expand Down
4 changes: 1 addition & 3 deletions mol/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import math
import os
from collections import OrderedDict
from typing import List

import numpy as np

Expand All @@ -23,7 +22,7 @@
from scm.plams.tools.units import Units

input_parser_available = "AMSBIN" in os.environ
from typing import Dict, List, Optional, Tuple, Union, overload
from typing import List, Optional, Tuple, overload

__all__ = ["Molecule"]

Expand Down Expand Up @@ -2343,7 +2342,6 @@ def get_translated_vectors(iat, neighbors, molcoords):
return

# Get the lattice vectors, and make sure there are 3 of them
nats = len(self)
latticevecs = []
for i in range(3):
if i < len(self.lattice):
Expand Down
Loading

0 comments on commit 8976c77

Please sign in to comment.