-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlennard_jones_potential_module.py
More file actions
72 lines (63 loc) · 2.64 KB
/
lennard_jones_potential_module.py
File metadata and controls
72 lines (63 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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
import tensorwrapper as tw
from simde import TotalEnergy
class LennardJonesPotential(pp.ModuleBase):
# 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
# ----------------------------------------------------------------------
E = tw.Tensor(np.array(E))
rv = self.results()
return pt.wrap_results(rv, E)
# --------------------------------------------------------------------------
def load_lennard_jones_potential(mm):
mm.add_module("Lennard-Jones", LennardJonesPotential())