-
Notifications
You must be signed in to change notification settings - Fork 0
__init__.py adding lenard-jones potential #5
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
c902b47
__init__.py adding lenard-jones potential
fcuantico 71d01bd
Change E to E(x0) and add __init__.py and change the name of the orig…
fcuantico 846f97b
Merge branch 'pyberny_addition' of github.com:NWChemEx/StructureFinde…
fcuantico 089d15d
lenard jones potential module added
fcuantico a0ad0a0
moved lennard-jones files to src
fcuantico 68bb191
Committing clang-format changes
github-actions[bot] eeb108f
Lennard Jones Module with tests
fcuantico fd1c4f6
LJ potential tests
fcuantico b64903b
Committing clang-format changes
github-actions[bot] 426ca98
lenard jones module PEP8 changes
fcuantico 67aba50
changes to __init__ and removal of lj_potential.py
fcuantico 3693597
__init__.py change from Ryan's coment
fcuantico 412bd2c
Committing clang-format changes
github-actions[bot] eb22c14
clean up
fcuantico 1dfcf78
spyproject folder deleted
fcuantico 9e906e3
fix return type
fcuantico 312cdcd
Committing clang-format changes
github-actions[bot] 41d271a
put band-aid on PyBerny
jlheflin 27a3497
Update tests/python/unit_tests/test_lennard_jones_potential/test_lenn…
ryanmrichard File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/python/structurefinder/lj_potential/lennard_jones_potential_module.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| # 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. | ||
| """ | ||
| @author: Felix Rojas | ||
| """ | ||
|
|
||
| import numpy as np | ||
| import pluginplay as pp | ||
| from simde import TotalEnergy | ||
|
|
||
|
|
||
| class LJ_potential(pp.ModuleBase): | ||
ryanmrichard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # Module Construct -------------------------------------------------------- | ||
| def __init__(self): | ||
| """ | ||
| This module Evaluates the Lennard-Jones 1D potential function (E) | ||
| """ | ||
| pp.ModuleBase.__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, | ||
| TYPE ---> Float | ||
| Returns | ||
| ------- | ||
| E: Lennard-Jonnes 1D potential Energy, | ||
| TYPE ---> Float | ||
| """ | ||
| pt = TotalEnergy() | ||
| 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 | ||
| #---------------------------------------------------------------------- | ||
| r = np.linalg.norm(coor_0 - coor_1) | ||
| #-------------- 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 | ||
| #---------------------------------------------------------------------- | ||
| rv = self.results() | ||
| return pt.wrap_results(rv, E) | ||
|
|
||
| #-------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def load_Lenard_Jones_potential(mm): | ||
| mm.add_module("Lenard-Jones", LJ_potential()) | ||
ryanmrichard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| # Copyright 2025 NWChemEx Community | ||
ryanmrichard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # | ||
| # 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 numpy as np | ||
| import plugandplay as pp | ||
| from simde import TotalEnergy | ||
|
|
||
|
|
||
| class LJ_potential(pp.ModuleBase): | ||
| # Module Construct -------------------------------------------------------- | ||
| def __init__(self): | ||
| """ | ||
| This module Evaluates the Lennard-Jones 1D potential function (E), and | ||
| calculates minus the gradient (Force) in Cartesian coordinates, | ||
| according to the relation | ||
| FC = - dE/dx | ||
| """ | ||
| pp.ModuleBase.__init__(self) | ||
| self.description("Lennard-Jones 1D potential function") | ||
| self.satisfies_property_type(TotalEnergy()) | ||
|
|
||
| #-------------------------------------------------------------------------- | ||
|
|
||
| # Module run_ member function --------------------------------------------- | ||
| def run_(self, inputs): | ||
| """ | ||
| Parameters | ||
| ---------- | ||
| inputs : x-coordinate, | ||
| TYPE ---> Float | ||
| Returns | ||
| ------- | ||
| E: Lennard-Jonnes 1D potential Energy, | ||
| TYPE ---> Float | ||
| FC: Force in cartesian coordinates evaluated at the given input, | ||
| acording to the relation | ||
| FC = - dE/dx | ||
| TYPE ---> Float | ||
| """ | ||
| pt = TotalEnergy() | ||
| x0 = pt.unwrap_inputs(inputs) | ||
| #-------------- LENNARD-JONES FUNCTION -------------------------------- | ||
| E = lambda x: 4 * ((1 / x**12) - (1 / x**6)) | ||
| #------------- ANALYTIC FORCE ----------------------------------------- | ||
| DE_x = -24 * ((2 / x0**13) - (1 / x0**7)) | ||
| FC = -DE_x | ||
| #---------------------------------------------------------------------- | ||
| rv = self.results() | ||
| return pt.wrap_results(rv, E(x0), FC) | ||
|
|
||
| #-------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| def load_Lenard_Jones_potential(mm): | ||
| mm.add_module("Lenard-Jones", LJ_potential()) | ||
13 changes: 13 additions & 0 deletions
13
tests/python/unit_tests/test_lennard_jones_potential/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. |
34 changes: 34 additions & 0 deletions
34
tests/python/unit_tests/test_lennard_jones_potential/test_LJ_potential.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 structurefinder | ||
| import nwchemex | ||
| import pluginplay as pp | ||
| import chemist | ||
| import unittest | ||
| from simde import TotalEnergy | ||
|
|
||
|
|
||
| class Test_Lennard_jones_potential(unittest.TestCase): | ||
ryanmrichard marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def test_lennard_jones_potential(self): | ||
| result = self.mm.run_as(TotalEnergy(), "Lenard-Jones", | ||
| chemist.ChemicalSystem(self.mol)) | ||
| self.assertEqual(result, -1.0) | ||
|
|
||
| def setUp(self): | ||
ryanmrichard marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| self.mm = pp.ModuleManager() | ||
| 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))) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.