From fada10389f171642b6e100e9d8d5dda8df765a1f Mon Sep 17 00:00:00 2001 From: "Jonathan M. Waldrop" Date: Fri, 8 Aug 2025 14:51:57 -0500 Subject: [PATCH] fixes from pre-commit --- .github/workflows/pull_request.yaml | 3 +- .github/.licenserc.yaml => .licenserc.yaml | 1 + docs/requirements.txt | 4 +- docs/source/conf.py | 81 +++++++++++-------- src/python/structurefinder/__init__.py | 4 +- .../lennard_jones_potential_module.py | 32 ++++---- .../structurefinder/pyberny/__init__.py | 29 ++++--- .../test_lennard_jones_potential.py | 18 +++-- .../test_optimizers/test_pybernyop.py | 17 ++-- .../python/unit_tests/test_structurefinder.py | 7 +- version.txt | 2 +- 11 files changed, 113 insertions(+), 85 deletions(-) rename .github/.licenserc.yaml => .licenserc.yaml (98%) diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml index 80bb11a..748c67c 100644 --- a/.github/workflows/pull_request.yaml +++ b/.github/workflows/pull_request.yaml @@ -24,7 +24,7 @@ jobs: check_formatting: uses: NWChemEx/.github/.github/workflows/check_formatting.yaml@master with: - license_config: ".github/.licenserc.yaml" + license_config: ".licenserc.yaml" cpp_source_dirs: "" # test_nwx_docs: @@ -36,4 +36,3 @@ jobs: uses: NWChemEx/.github/.github/workflows/test_nwx_library.yaml@master with: compilers: '["gcc-11", "clang-14"]' - diff --git a/.github/.licenserc.yaml b/.licenserc.yaml similarity index 98% rename from .github/.licenserc.yaml rename to .licenserc.yaml index ccc6cfb..2a46e35 100644 --- a/.github/.licenserc.yaml +++ b/.licenserc.yaml @@ -22,5 +22,6 @@ header: - LICENSE - version.txt - docs/source/nitpick_exceptions + - build/ comment: never diff --git a/docs/requirements.txt b/docs/requirements.txt index 48cd690..c239f7d 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -1,5 +1,5 @@ sphinx==v7.2.6 +sphinx-autoapi sphinx_rtd_theme==1.3.0 -sphinxcontrib-bibtex sphinx_tabs -sphinx-autoapi +sphinxcontrib-bibtex diff --git a/docs/source/conf.py b/docs/source/conf.py index df0ce3b..1f59ecc 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -21,30 +21,33 @@ # http://www.sphinx-doc.org/en/master/config import os -import sys # -- Project information ----------------------------------------------------- -project = u'StructureFinder' -copyright = u'2024, NWChemEx Community' -author = u'NWChemEx Community' +project = "StructureFinder" +copyright = "2024, NWChemEx Community" +author = "NWChemEx Community" # Get the version from version.txt -version = '1.0.0' +version = "1.0.0" # The full version, including alpha/beta/rc tags release = version # -- General configuration --------------------------------------------------- # We use numref which is introduced in Sphinx 1.3 -needs_sphinx = '1.3' +needs_sphinx = "1.3" # Add any Sphinx extension module names here, as strings. They can be # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.doctest', 'sphinx.ext.todo', 'sphinx.ext.coverage', - 'sphinx.ext.mathjax', 'sphinx.ext.githubpages', 'autoapi.extension' + "sphinx.ext.doctest", + "sphinx.ext.todo", + "sphinx.ext.coverage", + "sphinx.ext.mathjax", + "sphinx.ext.githubpages", + "autoapi.extension", ] dir_path = os.path.dirname(os.path.realpath(__file__)) doc_path = os.path.dirname(dir_path) @@ -57,17 +60,17 @@ # You can specify multiple suffix as a list of string: # # source_suffix = ['.rst', '.md'] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = 'en' +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. @@ -75,7 +78,7 @@ exclude_patterns = [] # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # Should figures be numbered? numfig = True @@ -85,7 +88,7 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the @@ -111,7 +114,7 @@ # -- Options for HTMLHelp output --------------------------------------------- # Output file base name for HTML help builder. -htmlhelp_basename = project + 'doc' +htmlhelp_basename = project + "doc" # -- Options for LaTeX output ------------------------------------------------ @@ -119,15 +122,12 @@ # The paper size ('letterpaper' or 'a4paper'). # # 'papersize': 'letterpaper', - # The font size ('10pt', '11pt' or '12pt'). # # 'pointsize': '10pt', - # Additional stuff for the LaTeX preamble. # # 'preamble': '', - # Latex figure (float) alignment # # 'figure_align': 'htbp', @@ -137,16 +137,22 @@ # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, project + '.tex', project + ' Documentation', author, - 'manual'), + ( + master_doc, + project + ".tex", + project + " Documentation", + author, + "manual", + ), ] # -- Options for manual page output ------------------------------------------ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). -man_pages = [(master_doc, project.lower(), project + ' Documentation', - [author], 1)] +man_pages = [ + (master_doc, project.lower(), project + " Documentation", [author], 1) +] # -- Options for Texinfo output ---------------------------------------------- @@ -154,23 +160,30 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, project, project + ' Documentation', author, project, - 'One line description of project.', 'Miscellaneous'), + ( + master_doc, + project, + project + " Documentation", + author, + project, + "One line description of project.", + "Miscellaneous", + ), ] # -- Extension configuration ------------------------------------------------- autoapi_dirs = [ - '../../src', + "../../src", # '../../tests', ] autoapi_add_toctree_entry = False autoapi_options = [ - 'members', - 'undoc-members', - 'private-members', - 'show-inheritance', - 'show-module-summary', - 'special-members', + "members", + "undoc-members", + "private-members", + "show-inheritance", + "show-module-summary", + "special-members", # 'imported-members', ] @@ -178,8 +191,8 @@ # This skips classes that derived from ModuleBase, because those classes will # have Module API documentation producable by PluginPlay def skip_pluginplay_modules(app, what, name, obj, skip, options): - bases = obj.obj['bases'] if 'bases' in obj.obj.keys() else [] - if 'pluginplay.ModuleBase' in bases: + bases = obj.obj["bases"] if "bases" in obj.obj.keys() else [] + if "pluginplay.ModuleBase" in bases: skip = True return skip @@ -191,7 +204,7 @@ def setup(sphinx): # -- Options for intersphinx extension --------------------------------------- # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'https://docs.python.org/': None} +intersphinx_mapping = {"https://docs.python.org/": None} # -- Options for todo extension ---------------------------------------------- @@ -203,7 +216,7 @@ def setup(sphinx): # Nitpick requires all references to be resolved # This will ignore those that references that can't be linked nitpick_ignore = [] -for line in open('nitpick_exceptions'): +for line in open("nitpick_exceptions"): if line.strip() == "" or line.startswith("#"): continue dtype, target = line.split(None, 1) diff --git a/src/python/structurefinder/__init__.py b/src/python/structurefinder/__init__.py index 4de7eee..7f6f762 100644 --- a/src/python/structurefinder/__init__.py +++ b/src/python/structurefinder/__init__.py @@ -12,8 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +from .lj_potential.lennard_jones_potential_module import ( + load_lennard_jones_potential, +) from .pyberny import load_pyberny_modules -from .lj_potential.lennard_jones_potential_module import load_lennard_jones_potential def load_modules(mm): diff --git a/src/python/structurefinder/lj_potential/lennard_jones_potential_module.py b/src/python/structurefinder/lj_potential/lennard_jones_potential_module.py index 6d67d1b..4cdd49e 100644 --- a/src/python/structurefinder/lj_potential/lennard_jones_potential_module.py +++ b/src/python/structurefinder/lj_potential/lennard_jones_potential_module.py @@ -17,8 +17,8 @@ import numpy as np import pluginplay as pp -from simde import TotalEnergy import tensorwrapper as tw +from simde import TotalEnergy class LennardJonesPotential(pp.ModuleBase): @@ -31,41 +31,41 @@ def __init__(self): self.description("Lennard-Jones 1D potential function") self.satisfies_property_type(TotalEnergy()) - #-------------------------------------------------------------------------- + # -------------------------------------------------------------------------- # Module run_ member function --------------------------------------------- def run_(self, inputs, submods): """ Parameters ---------- - inputs : Diatomic distance, + inputs : Diatomic distance, TYPE ---> Float - + Returns ------- - E: Lennard-Jonnes 1D potential Energy, - TYPE ---> Float + E: Lennard-Jonnes 1D potential Energy, + TYPE ---> Float """ pt = TotalEnergy() - chem_sys, = pt.unwrap_inputs(inputs) + (chem_sys,) = pt.unwrap_inputs(inputs) mol = chem_sys.molecule coor_0 = np.array([mol.at(0).x, mol.at(0).y, mol.at(0).z]) coor_1 = np.array([mol.at(1).x, mol.at(1).y, mol.at(1).z]) - #---------------------------------------------------------------------- - assert (mol.size() == 2) #<--- To check molcule size contains 2-atoms - #---------------------------------------------------------------------- + # ---------------------------------------------------------------------- + assert mol.size() == 2 # <--- To check molcule size contains 2-atoms + # ---------------------------------------------------------------------- r = np.linalg.norm(coor_0 - coor_1) - #-------------- LENNARD-JONES FUNCTION -------------------------------- + # -------------- LENNARD-JONES FUNCTION -------------------------------- E = 4 * ((1 / r**12) - (1 / r**6)) - #------------- ANALYTIC FORCE ----------------------------------------- - DE_x = -24 * ((2 / r**13) - (1 / r**7)) - FC = -DE_x - #---------------------------------------------------------------------- + # ------------- ANALYTIC FORCE ----------------------------------------- + # DE_x = -24 * ((2 / r**13) - (1 / r**7)) + # FC = -DE_x + # ---------------------------------------------------------------------- E = tw.Tensor(np.array(E)) rv = self.results() return pt.wrap_results(rv, E) - #-------------------------------------------------------------------------- + # -------------------------------------------------------------------------- def load_lennard_jones_potential(mm): diff --git a/src/python/structurefinder/pyberny/__init__.py b/src/python/structurefinder/pyberny/__init__.py index 8cf0ac2..6f0a9b4 100644 --- a/src/python/structurefinder/pyberny/__init__.py +++ b/src/python/structurefinder/pyberny/__init__.py @@ -12,20 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. +import chemist +import numpy as np import pluginplay as pp +from berny import Berny, geomlib from simde import ( EnergyNuclearGradientStdVectorD, - TotalEnergyNuclearOptimization, MoleculeFromString, TotalEnergy, + TotalEnergyNuclearOptimization, ) -from berny import Berny, geomlib -import chemist -import numpy as np class GeomoptViaPyberny(pp.ModuleBase): - def __init__(self): pp.ModuleBase.__init__(self) self.satisfies_property_type(TotalEnergyNuclearOptimization()) @@ -43,10 +42,18 @@ def run_(self, inputs, submods): xyz = "" xyz += str(molecule.size()) + "\n\n" - #TODO ensure points == molecule.nuclei.charges.point_set + # TODO ensure points == molecule.nuclei.charges.point_set for i in range(points.size()): - xyz += (molecule.at(i).name + " " + str(points.at(i).x) + " " + - str(points.at(i).y) + " " + str(points.at(i).z) + "\n") + xyz += ( + molecule.at(i).name + + " " + + str(points.at(i).x) + + " " + + str(points.at(i).y) + + " " + + str(points.at(i).z) + + "\n" + ) # Loads the geometry string into the Berny optimizer # object. @@ -58,7 +65,8 @@ def run_(self, inputs, submods): lines = geom2xyz.split("\n") mol_string = "\n".join(lines[2:]) xyz2chem_mol = submods["StringConv"].run_as( - MoleculeFromString(), mol_string) + MoleculeFromString(), mol_string + ) geom = chemist.ChemicalSystem(xyz2chem_mol) geom_nuclei = geom.molecule.nuclei.as_nuclei() geom_points = geom_nuclei.charges.point_set.as_point_set() @@ -66,7 +74,8 @@ def run_(self, inputs, submods): # Main optimizer operation energy = submods["Energy"].run_as(TotalEnergy(), geom) gradients = submods["Gradient"].run_as( - EnergyNuclearGradientStdVectorD(), geom, geom_points) + EnergyNuclearGradientStdVectorD(), geom, geom_points + ) optimizer.send((np.array(energy).item(), gradients)) opt_geom_nuclei = geom.molecule.nuclei.as_nuclei() diff --git a/tests/python/unit_tests/test_lennard_jones_potential/test_lennard_jones_potential.py b/tests/python/unit_tests/test_lennard_jones_potential/test_lennard_jones_potential.py index 0dc59c1..fb02af1 100644 --- a/tests/python/unit_tests/test_lennard_jones_potential/test_lennard_jones_potential.py +++ b/tests/python/unit_tests/test_lennard_jones_potential/test_lennard_jones_potential.py @@ -11,20 +11,20 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import unittest + +import chemist import numpy as np -import structurefinder -import nwchemex import pluginplay as pp -import chemist -import unittest +import structurefinder from simde import TotalEnergy class TestLennardJonesPotential(unittest.TestCase): - def test_lennard_jones_potential(self): - result = self.mm.run_as(TotalEnergy(), "Lennard-Jones", - chemist.ChemicalSystem(self.mol)) + result = self.mm.run_as( + TotalEnergy(), "Lennard-Jones", chemist.ChemicalSystem(self.mol) + ) self.assertEqual(np.array(result).item(), -1.0) def setUp(self): @@ -32,4 +32,6 @@ def setUp(self): structurefinder.load_modules(self.mm) self.mol = chemist.Molecule() self.mol.push_back(chemist.Atom("H", 1, 1.0079, 0.0, 0.0, 0.0)) - self.mol.push_back(chemist.Atom("H", 1, 1.0079, 0.0, 0.0, 2**(1 / 6))) + self.mol.push_back( + chemist.Atom("H", 1, 1.0079, 0.0, 0.0, 2 ** (1 / 6)) + ) diff --git a/tests/python/unit_tests/test_optimizers/test_pybernyop.py b/tests/python/unit_tests/test_optimizers/test_pybernyop.py index 22da6c0..7ec5471 100644 --- a/tests/python/unit_tests/test_optimizers/test_pybernyop.py +++ b/tests/python/unit_tests/test_optimizers/test_pybernyop.py @@ -12,25 +12,25 @@ # See the License for the specific language governing permissions and # limitations under the License. -import structurefinder -import nwchemex +import unittest + +import chemist import numpy as np +import nwchemex import pluginplay as pp -import chemist -import unittest +import structurefinder from simde import TotalEnergyNuclearOptimization def diatomic_bond_distance(coords): val = 0 for i in range(int(len(coords) / 2)): - val += (coords[i] - coords[i + 3])**2 + val += (coords[i] - coords[i + 3]) ** 2 distance = np.sqrt(val) return distance class Test_optimize_pyberny(unittest.TestCase): - def test_optimize_pyberny(self): mm = pp.ModuleManager() nwchemex.load_modules(mm) @@ -47,8 +47,9 @@ def test_optimize_pyberny(self): pyberny_mod.change_submod("Gradient", nwchem_grad_mod) pyberny_mod.change_submod("StringConv", string_conv_mod) - energy, points = pyberny_mod.run_as(TotalEnergyNuclearOptimization(), - self.sys, self.point_set_i) + energy, points = pyberny_mod.run_as( + TotalEnergyNuclearOptimization(), self.sys, self.point_set_i + ) coords = [] for atom in range(points.size()): diff --git a/tests/python/unit_tests/test_structurefinder.py b/tests/python/unit_tests/test_structurefinder.py index b3ef6cd..ee4e8e0 100644 --- a/tests/python/unit_tests/test_structurefinder.py +++ b/tests/python/unit_tests/test_structurefinder.py @@ -15,16 +15,17 @@ # import os -import parallelzone as pz import sys import unittest -if __name__ == '__main__': +import parallelzone as pz + +if __name__ == "__main__": rv = pz.runtime.RuntimeView() my_dir = os.path.dirname(os.path.realpath(__file__)) root_dir = os.path.dirname(os.path.dirname(os.path.dirname(my_dir))) - src_dir = os.path.join(root_dir, 'src', 'python') + src_dir = os.path.join(root_dir, "src", "python") sys.path.append(src_dir) loader = unittest.TestLoader() diff --git a/version.txt b/version.txt index bd52db8..77d6f4c 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -0.0.0 \ No newline at end of file +0.0.0