diff --git a/.github/.licenserc.yaml b/.github/.licenserc.yaml new file mode 100644 index 0000000..ccc6cfb --- /dev/null +++ b/.github/.licenserc.yaml @@ -0,0 +1,26 @@ +# Copyright 2021 NWChemEx-Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. +# +header: + license: + spdx-id: Apache-2.0 + copyright-owner: NWChemEx Community + + paths-ignore: + - .github/ + - LICENSE + - version.txt + - docs/source/nitpick_exceptions + + comment: never diff --git a/.github/workflows/merge.yaml b/.github/workflows/merge.yaml new file mode 100644 index 0000000..74b3366 --- /dev/null +++ b/.github/workflows/merge.yaml @@ -0,0 +1,29 @@ +# Copyright 2024 NWChemEx Community +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. +# + +name: .github Merge Workflow + +on: + push: + branches: + - master + +jobs: + Common-Merge: + uses: NWChemEx/.github/.github/workflows/common_merge.yaml@master + with: + doc_target: '' + generate_module_docs: true + secrets: inherit diff --git a/.github/workflows/pull_request.yaml b/.github/workflows/pull_request.yaml new file mode 100644 index 0000000..71746a6 --- /dev/null +++ b/.github/workflows/pull_request.yaml @@ -0,0 +1,31 @@ +# Copyright 2024 NWChemEx Community +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. +# + +name: .github Pull Request Workflow + +on: + pull_request: + branches: + - master + +jobs: + Common-Pull-Request: + uses: NWChemEx/.github/.github/workflows/common_pull_request.yaml@master + with: + config_file: '.github/.licenserc.yaml' + source_dir: '' + compilers: '["gcc-11", "clang-14"]' + doc_target: '' + secrets: inherit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ebb5abb --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +# Copyright 2024 NWChemEx Community +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +__pycache__/ +build/ +venv/ +install/ diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..056a394 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,88 @@ +# Copyright 2024 NWChemEx Community +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +cmake_minimum_required(VERSION 3.14) + +## Set Project and Version +file(STRINGS "${CMAKE_CURRENT_SOURCE_DIR}/version.txt" VERSION) +project(structurefinder VERSION "${VERSION}" LANGUAGES CXX) + +## Get CMaize +include(cmake/get_nwx_cmake.cmake) +include(nwx_versions) +include(get_cmaize) + +## Paths ## +set(${PROJECT_NAME}_INC_DIR "${CMAKE_CURRENT_LIST_DIR}/include/${PROJECT_NAME}") +set(${PROJECT_NAME}_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/src/${PROJECT_NAME}") +set(${PROJECT_NAME}_TESTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tests") +set(${PROJECT_NAME}_PYTHON_DIR "${CMAKE_CURRENT_SOURCE_DIR}/src/python") +set(${PROJECT_NAME}_PYTHON_TEST_DIR "${${PROJECT_NAME}_TESTS_DIR}/python") + +## Options ## +cmaize_option_list( + BUILD_TESTING OFF "Should the tests be built?" + BUILD_PYBIND11_PYBINDINGS ON "Use Pybind11 to build Python bindings?" +) + +## Find or build dependencies ## +cmaize_find_or_build_dependency( + simde + URL github.com/NWChemEx/SimDE + VERSION master + BUILD_TARGET simde + FIND_TARGET nwx::simde + CMAKE_ARGS BUILD_TESTING=OFF + BUILD_PYBIND11_PYBINDINGS=${BUILD_PYBIND11_PYBINDINGS} + BUILD_DOCS=OFF +) + +cmaize_find_or_build_dependency( + pyberny + PACKAGE_MANAGER pip +) + +## Add libraries ## +add_library(${PROJECT_NAME} INTERFACE) +target_link_libraries(${PROJECT_NAME} INTERFACE simde pyberny) + +## Build tests ## +if("${BUILD_TESTING}") + include(CTest) + include(nwx_pybind11) + + ## Add Tests ## + cmaize_find_or_build_dependency( + nwchemex + URL github.com/NWChemEx/NWChemEx + BUILD_TARGET nwchemex + FIND_TARGET nwx::nwchemex + CMAKE_ARGS BUILD_TESTING=OFF + BUILD_FULL_CHEMCACHE=OFF + ) + + nwx_pybind11_tests( + py_${PROJECT_NAME} + "${${PROJECT_NAME}_PYTHON_TEST_DIR}/unit_tests/test_${PROJECT_NAME}.py" + DEPENDS nwchemex + SUBMODULES simde chemist pluginplay parallelzone friendzone chemcache nwchemex + ) + +endif() + +## Add package ## +install( + DIRECTORY "${${PROJECT_NAME}_PYTHON_DIR}/${PROJECT_NAME}" + DESTINATION "${NWX_MODULE_DIRECTORY}" +) diff --git a/README.md b/README.md index 3f2c16b..4218030 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,18 @@ + + # StructureFinder Repo for geometry optimization, transition states, etc. Much of this repo will be Python based, providing interfaces to geomeTRIC, pyBerny, ASE NEB, etc. diff --git a/cmake/get_cmaize.cmake b/cmake/get_cmaize.cmake new file mode 100644 index 0000000..df3d9c3 --- /dev/null +++ b/cmake/get_cmaize.cmake @@ -0,0 +1,49 @@ +# Copyright 2024 NWChemEx Community +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +function(get_cmaize) + + if("${CMAIZE_VERSION}" STREQUAL "") + set(CMAIZE_VERSION ca0f41e6d42829f9afb3c02f68ba4030fff6fee7 ) + endif() + + # Store whether we are building tests or not, then turn off the tests + if(BUILD_TESTING) + set(build_testing_old "${BUILD_TESTING}") + endif() + set(BUILD_TESTING OFF CACHE BOOL "" FORCE) + + # Download CMakePP and bring it into scope + include(FetchContent) + FetchContent_Declare( + cmaize + GIT_REPOSITORY https://github.com/CMakePP/CMaize + GIT_TAG ${CMAIZE_VERSION} + ) + FetchContent_MakeAvailable(cmaize) + + # Restore the previous value, if set + # Unset otherwise + if(build_testing_old) + set(BUILD_TESTING "${build_testing_old}" CACHE BOOL "" FORCE) + else() + unset(BUILD_TESTING CACHE) + endif() +endfunction() + +# Call the function we just wrote to get CMaize +get_cmaize() + +# Include CMaize +include(cmaize/cmaize) diff --git a/cmake/get_nwx_cmake.cmake b/cmake/get_nwx_cmake.cmake new file mode 100644 index 0000000..de8c4bc --- /dev/null +++ b/cmake/get_nwx_cmake.cmake @@ -0,0 +1,31 @@ +# Copyright 2024 NWChemEx Community +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +include_guard() + +macro(get_nwx_cmake) + include(FetchContent) + FetchContent_Declare( + nwx_cmake + GIT_REPOSITORY https://github.com/NWChemEx/NWXCMake + ) + FetchContent_MakeAvailable(nwx_cmake) + set( + CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${nwx_cmake_SOURCE_DIR}/cmake" + CACHE STRING "" + FORCE + ) +endmacro() + +get_nwx_cmake() diff --git a/docs/Makefile b/docs/Makefile new file mode 100644 index 0000000..7691d6c --- /dev/null +++ b/docs/Makefile @@ -0,0 +1,34 @@ +# Copyright 2024 NWChemEx Community +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +# Minimal makefile for Sphinx documentation +# + +# You can set these variables from the command line. +SPHINXOPTS = +SPHINXBUILD = sphinx-build +SPHINXPROJ = structurefinder +SOURCEDIR = source +BUILDDIR = build + +# Put it first so that "make" without argument is like "make help". +help: + @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) + +.PHONY: help Makefile + +# Catch-all target: route all unknown targets to Sphinx using the new +# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). +%: Makefile + @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..dfddd98 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,18 @@ + + +General instructions for building documentation found throughout the NWChemEx project are available at: +https://github.com/NWChemEx/NWChemEx/blob/master/docs/README.md diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..48cd690 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,5 @@ +sphinx==v7.2.6 +sphinx_rtd_theme==1.3.0 +sphinxcontrib-bibtex +sphinx_tabs +sphinx-autoapi diff --git a/docs/source/conf.py b/docs/source/conf.py new file mode 100644 index 0000000..df0ce3b --- /dev/null +++ b/docs/source/conf.py @@ -0,0 +1,211 @@ +# -*- coding: utf-8 -*- +# Copyright 2023 NWChemEx-Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +# +# Configuration file for the Sphinx documentation builder. +# +# This file does only contain a selection of the most common options. For a +# full list see the documentation: +# 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' + +# Get the version from version.txt +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' + +# 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' +] +dir_path = os.path.dirname(os.path.realpath(__file__)) +doc_path = os.path.dirname(dir_path) +root_path = os.path.dirname(doc_path) + +# Add any paths that contain templates here, relative to this directory. +# templates_path = ['_templates'] + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The master toctree document. +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' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path . +exclude_patterns = [] + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# Should figures be numbered? +numfig = True + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +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 +# documentation. +# +# html_theme_options = {} + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +# html_static_path = ['_static'] + +# Custom sidebar templates, must be a dictionary that maps document names +# to template names. +# +# The default sidebars (for documents that don't match any pattern) are +# defined by theme itself. Builtin themes are using these templates by +# default: ``['localtoc.html', 'relations.html', 'sourcelink.html', +# 'searchbox.html']``. +# +# html_sidebars = {} + +# -- Options for HTMLHelp output --------------------------------------------- + +# Output file base name for HTML help builder. +htmlhelp_basename = project + 'doc' + +# -- Options for LaTeX output ------------------------------------------------ + +latex_elements = { + # 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', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (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)] + +# -- Options for Texinfo output ---------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (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'), +] + +# -- Extension configuration ------------------------------------------------- +autoapi_dirs = [ + '../../src', + # '../../tests', +] +autoapi_add_toctree_entry = False +autoapi_options = [ + 'members', + 'undoc-members', + 'private-members', + 'show-inheritance', + 'show-module-summary', + 'special-members', + # 'imported-members', +] + + +# 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: + skip = True + return skip + + +def setup(sphinx): + sphinx.connect("autoapi-skip-member", skip_pluginplay_modules) + + +# -- Options for intersphinx extension --------------------------------------- + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = {'https://docs.python.org/': None} + +# -- Options for todo extension ---------------------------------------------- + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True + +# -- Nitpick Ignore options -------------------------------------------------- + +# 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'): + if line.strip() == "" or line.startswith("#"): + continue + dtype, target = line.split(None, 1) + target = target.strip() + nitpick_ignore.append((dtype, target)) diff --git a/docs/source/index.rst b/docs/source/index.rst new file mode 100644 index 0000000..437a581 --- /dev/null +++ b/docs/source/index.rst @@ -0,0 +1,24 @@ +.. Copyright 2024 NWChemEx Community +.. +.. Licensed under the Apache License, Version 2.0 (the "License"); +.. you may not use this file except in compliance with the License. +.. You may obtain a copy of the License at +.. +.. http://www.apache.org/licenses/LICENSE-2.0 +.. +.. Unless required by applicable law or agreed to in writing, software +.. distributed under the License is distributed on an "AS IS" BASIS, +.. 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. + +############### +StructureFinder +############### + +.. toctree:: + :maxdepth: 2 + :caption: APIs: + + module_api/index + C++ API diff --git a/docs/source/module_api/index.rst b/docs/source/module_api/index.rst new file mode 100644 index 0000000..400e329 --- /dev/null +++ b/docs/source/module_api/index.rst @@ -0,0 +1,21 @@ +.. Copyright 2024 NWChemEx Community +.. +.. Licensed under the Apache License, Version 2.0 (the "License"); +.. you may not use this file except in compliance with the License. +.. You may obtain a copy of the License at +.. +.. http://www.apache.org/licenses/LICENSE-2.0 +.. +.. Unless required by applicable law or agreed to in writing, software +.. distributed under the License is distributed on an "AS IS" BASIS, +.. 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. + +********** +Module API +********** + +.. toctree:: + :maxdepth: 1 + :caption: Packages diff --git a/docs/source/nitpick_exceptions b/docs/source/nitpick_exceptions new file mode 100644 index 0000000..ec1931a --- /dev/null +++ b/docs/source/nitpick_exceptions @@ -0,0 +1,5 @@ +py:class pluginplay.ModuleManager +py:class pluginplay.PropertyType +py:class chemist.ChemicalSystem + +py:class Varies depending on the requested property diff --git a/src/python/structurefinder/__init__.py b/src/python/structurefinder/__init__.py new file mode 100644 index 0000000..b30b4bf --- /dev/null +++ b/src/python/structurefinder/__init__.py @@ -0,0 +1,22 @@ +# Copyright 2024 NWChemEx Community +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. + +from .pyberny import load_pyberny_modules + + +def load_modules(mm): + """ + Loads the collection of all modules provided by StructureFinder. + """ + load_pyberny_modules(mm) diff --git a/src/python/structurefinder/lj_potential/__init__.py b/src/python/structurefinder/lj_potential/__init__.py new file mode 100644 index 0000000..a8d4745 --- /dev/null +++ b/src/python/structurefinder/lj_potential/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2025 NWChemEx Community +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. diff --git a/src/python/structurefinder/pyberny/__init__.py b/src/python/structurefinder/pyberny/__init__.py new file mode 100644 index 0000000..886f192 --- /dev/null +++ b/src/python/structurefinder/pyberny/__init__.py @@ -0,0 +1,87 @@ +# Copyright 2023 NWChemEx-Project +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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 pluginplay as pp +from simde import EnergyNuclearGradientStdVectorD, TotalEnergy, MoleculeFromString +from berny import Berny, geomlib +import chemist + + +class GeomoptViaPyberny(pp.ModuleBase): + + def __init__(self): + pp.ModuleBase.__init__(self) + self.satisfies_property_type(TotalEnergy()) + self.description("Performs PyBerny optimization") + self.add_submodule(TotalEnergy(), "Energy") + self.add_submodule(EnergyNuclearGradientStdVectorD(), "Gradient") + self.add_submodule(MoleculeFromString(), "StringConv") + + def run_(self, inputs, submods): + pt = TotalEnergy() + mol, = pt.unwrap_inputs(inputs) + molecule = mol.molecule + + # Convert Chemist Chemical System to XYZ + xyz = "" + xyz += (str(molecule.size()) + "\n\n") + for i in range(molecule.size()): + xyz += (molecule.at(i).name + " " + str(molecule.at(i).x) + " " + + str(molecule.at(i).y) + " " + str(molecule.at(i).z) + "\n") + + # Loads the geometry string into the Berny optimizer + # object. + optimizer = Berny(geomlib.loads(xyz, fmt='xyz')) + + for geom in optimizer: + + # Converts the "Berny" geometry object to Chemical System + geom2xyz = geom.dumps('xyz') + print('Berny Geom to XYZ value: \n' + geom2xyz + '\n') + lines = geom2xyz.split('\n') + print('Lines of geom2xyz: \n' + str(lines) + '\n') + mol_string = '\n'.join(lines[2:]) + print('Lines to string: \n' + mol_string + '\n') + xyz2chem_mol = submods["StringConv"].run_as( + MoleculeFromString(), mol_string) + print('String conversion from xyz to chem sys: \n' + + str(xyz2chem_mol.nuclei) + '\n') + geom = chemist.ChemicalSystem(xyz2chem_mol) + print('Chemical system of xyz2chem_mol: \n' + + str(geom.molecule.nuclei) + '\n') + geom_nuclei = geom.molecule.nuclei.as_nuclei() + geom_points = geom_nuclei.charges.point_set + + # Main optimizer operation + energy = submods["Energy"].run_as(TotalEnergy(), geom) + print('Interim energy: \n' + str(energy) + '\n') + gradients = submods["Gradient"].run_as( + EnergyNuclearGradientStdVectorD(), geom, + geom_points.as_point_set()) + print('Interim gradient: \n' + str(gradients) + '\n') + optimizer.send((energy, gradients)) + + opt_geom = geom.molecule.nuclei + print( + 'Resulting relaxed geometry (assigned to variable opt_geom): \n' + + str(opt_geom)) + # Optimized energy is of type "float" + e = energy + print(e) + rv = self.results() + return pt.wrap_results(rv, e) + + +def load_pyberny_modules(mm): + mm.add_module("PyBerny", GeomoptViaPyberny()) diff --git a/tests/python/unit_tests/test_optimizers/__init__.py b/tests/python/unit_tests/test_optimizers/__init__.py new file mode 100644 index 0000000..f54d13e --- /dev/null +++ b/tests/python/unit_tests/test_optimizers/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2024 NWChemEx Community +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. diff --git a/tests/python/unit_tests/test_optimizers/test_pybernyop.py b/tests/python/unit_tests/test_optimizers/test_pybernyop.py new file mode 100644 index 0000000..26611e6 --- /dev/null +++ b/tests/python/unit_tests/test_optimizers/test_pybernyop.py @@ -0,0 +1,43 @@ +# Copyright 2024 NWChemEx Community +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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 structurefinder +import nwchemex +import pluginplay as pp +import chemist +import unittest +from simde import TotalEnergy + + +class Test_optimize_pyberny(unittest.TestCase): + + def test_optimize_pyberny(self): + mm = pp.ModuleManager() + nwchemex.load_modules(mm) + structurefinder.load_modules(mm) + mm.change_input("NWChem : SCF", "basis set", "sto-3g") + mm.change_input("NWChem : SCF Gradient", "basis set", "sto-3g") + mm.change_submod("PyBerny", "Gradient", "NWChem : SCF Gradient") + mm.change_submod("PyBerny", "Energy", "NWChem : SCF") + mm.change_submod("Pyberny", "StringConv", + "ChemicalSystem via QCElemental") + egy = mm.run_as(TotalEnergy(), "PyBerny", + chemist.ChemicalSystem(self.mol)) + print("Energy = " + str(egy)) + self.assertAlmostEqual(egy, -1.117505879316, 10) + + def setUp(self): + 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, 1.0)) diff --git a/tests/python/unit_tests/test_structurefinder.py b/tests/python/unit_tests/test_structurefinder.py new file mode 100644 index 0000000..b3ef6cd --- /dev/null +++ b/tests/python/unit_tests/test_structurefinder.py @@ -0,0 +1,34 @@ +# +# Copyright 2024 NWChemEx Community +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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 os +import parallelzone as pz +import sys +import unittest + +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') + sys.path.append(src_dir) + + loader = unittest.TestLoader() + tests = loader.discover(my_dir) + testrunner = unittest.runner.TextTestRunner() + ret = not testrunner.run(tests).wasSuccessful() + sys.exit(ret) diff --git a/version.txt b/version.txt new file mode 100644 index 0000000..bd52db8 --- /dev/null +++ b/version.txt @@ -0,0 +1 @@ +0.0.0 \ No newline at end of file