Skip to content

Commit

Permalink
more angle progress
Browse files Browse the repository at this point in the history
  • Loading branch information
jrudz committed Sep 25, 2024
1 parent d039677 commit 8c0399e
Show file tree
Hide file tree
Showing 2 changed files with 260 additions and 39 deletions.
153 changes: 117 additions & 36 deletions src/nomad_simulations/schema_packages/force_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,6 @@ def normalize(self, archive, logger) -> None:
)

if self.forces is not None and self.energies is None:
print('in gen energies')
try:
# generated energies from forces numerically using spline
self.energies = self.compute_energies(
Expand Down Expand Up @@ -308,8 +307,38 @@ def normalize(self, archive, logger) -> None:
)


class PolynomialPotential(Potential):
class PolynomialForceConstant(ParameterEntry):
"""
Section defining a force constant for a potential of polynomial form.
"""

name = Quantity(
type=str,
shape=[],
description="""
Name of the force constant.
""",
)

exponent = Quantity(
type=np.int32,
shape=[],
description="""
Exponent for this term in the polynomial.
""",
)

value = Quantity(
type=np.float64,
shape=[],
description="""
Value of the force constant.
""",
)


class PolynomialPotential(Potential):
r"""
Abstract class for potentials with polynomial form:
$V(x) = [\left k_1 (x - x_0) + k_2 (x - x_0)^2 + x_3 (x - x_0)^3 + \dots + C$,
where $\{x_1, x_2, x_3 \dots}$ are the `force_constants` for each term in the polynomial
Expand All @@ -318,7 +347,7 @@ class PolynomialPotential(Potential):
"""

force_constants = SubSection(
sub_section=ParameterEntry.m_def,
sub_section=PolynomialForceConstant.m_def,
repeats=True,
description="""
List of force constants value and corresponding unit for polynomial potentials.
Expand All @@ -329,13 +358,17 @@ def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)

self.name = 'PolynomialPotential'
if not self.functional_form:
self.functional_form = 'polynomial'
elif self.functional_form != 'polynomial':
logger.warning('Incorrect functional form set for PolynomialPotential.')


class BondPotential(Potential):
"""
Section containing information about bond potentials.
Suggested types are: harmonic, cubic, Morse, fene, tabulated
Suggested types are: harmonic, cubic, polynomial, Morse, fene, tabulated
"""

equilibrium_value = Quantity(
Expand Down Expand Up @@ -419,47 +452,19 @@ def normalize(self, archive, logger) -> None:
logger.warning('Incorrect functional form set for CubicBond.')


# TODO Add Fourth Power potential from gromacs, might want to make it a more general quartic polynomial, even though it's not as general
# class QuarticBond(BondPotential):
# r"""
# Section containing information about a Cubic bond potential:
# $V(r) = \frac{1}{2} k_r (r - r_0)^2 + \frac{1}{3} k_c (r - r_0)^3 + C$,
# where $k_r$ is the (harmonic) `force_constant`, $k_c$ is the `force_constant_cubic`,
# and $r_0$ is the `equilibrium_value` of $r$.
# C is an arbitrary constant (not stored).
# """

# force_constant_cubic = Quantity(
# type=np.float64,
# shape=[],
# unit='J / m**3',
# description="""
# Specifies the cubic force constant of the bond potential.
# """,
# )

# def normalize(self, archive, logger) -> None:
# super().normalize(archive, logger)

# self.name = 'CubicBond'
# if not self.functional_form:
# self.functional_form = 'cubic'
# elif self.functional_form != 'cubic':
# logger.warning('Incorrect functional form set for CubicBond.')


class PolynomialBond(PolynomialPotential, BondPotential):
"""
Section containing information about a polynomial bond potential:
"""

def __init__(self):
super().__init__()
docstring = PolynomialPotential.__doc__
pattern = r'\$V\(x\)(.*?)(\(not stored\)\.)'
match = re.search(pattern, docstring, re.DOTALL)
extracted_text = '<functional form missing>'
if match:
extracted_text = match.group(1).strip()
extracted_text = match.group().strip() # .group(1).strip()
self.__doc__ = rf"""{self.__doc__} {extracted_text}.
Here the dependent variable of the potential, $x$, corresponds to the bond distance."""

Expand Down Expand Up @@ -572,7 +577,7 @@ class AnglePotential(Potential):
"""
Section containing information about angle potentials.
Suggested types are: harmonic, cosine, fourier_series, urey_bradley, tabulated
Suggested types are: harmonic, cosine, restricted_cosinse, fourier_series, urey_bradley, polynomial, tabulated
"""

equilibrium_value = Quantity(
Expand Down Expand Up @@ -745,12 +750,13 @@ class PolynomialAngle(PolynomialPotential, AnglePotential):
"""

def __init__(self):
super().__init__()
docstring = PolynomialPotential.__doc__
pattern = r'\$V\(x\)(.*?)(\(not stored\)\.)'
match = re.search(pattern, docstring, re.DOTALL)
extracted_text = '<functional form missing>'
if match:
extracted_text = match.group(1).strip()
extracted_text = match.group().strip() # .group(1).strip()
self.__doc__ = rf"""{self.__doc__} {extracted_text}.
Here the dependent variable of the potential, $x$, corresponds to the angle between three particles."""

Expand Down Expand Up @@ -790,6 +796,81 @@ def normalize(self, archive, logger) -> None:
self.name = 'TabulatedAngle'


class DihedralPotential(Potential):
"""
Section containing information about dihedral potentials.
Suggested types are: fourier_series, tabulated
# ? Something about angle convention?
"""

equilibrium_value = Quantity(
type=np.float64,
unit='degree',
shape=[],
description="""
Specifies the equilibrium dihedral angle.
""",
)

force_constant = Quantity(
type=np.float64,
shape=[],
unit='J / degree**2',
description="""
Specifies the force constant of the dihedral angle potential.
""",
)

def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)

self.name = 'DihedralPotential'
if not self.type:
self.type = 'dihedral'
elif self.type != 'dihedral':
logger.warning('Incorrect type set for DihedralPotential.')

if self.n_particles:
if self.n_particles != 4:
logger.warning(
'Incorrect number of particles set for DihedralPotential.'
)
else:
self.n_particles = 4


class TabulatedDihedral(DihedralPotential, TabulatedPotential):
"""
Section containing information about a tabulated bond potential. The value of the potential and/or force
is stored for a set of corresponding bin distances.
"""

bins = Quantity(
type=np.float64,
unit='degree',
shape=[],
description="""
List of bin dihedral angles.
""",
)

forces = Quantity(
type=np.float64,
unit='J/degree',
shape=[],
description="""
List of force values associated with each bin.
""",
)

def normalize(self, archive, logger) -> None:
super().normalize(archive, logger)

self.name = 'TabulatedDihedral'


class ForceField(ModelMethod):
"""
Section containing the parameters of a (classical, particle-based) force field model.
Expand Down
Loading

1 comment on commit 8c0399e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
src/nomad_simulations
   __init__.py4250%3–4
   _version.py11282%5–6
src/nomad_simulations/schema_packages
   __init__.py14286%53–55
   atoms_state.py1902189%31–33, 219–222, 246, 301–302, 370–371, 373, 555, 567–568, 629–633, 648–652, 659
   basis_set.py2402888%8–9, 122–133, 172–185, 208, 391–395, 417–418, 462–465, 584, 615, 617
   force_field.py2855979%135, 141, 191, 200, 214–215, 219, 224, 259–265, 298–304, 363–364, 399–400, 404, 423–424, 451–452, 510–511, 515–516, 542–543, 607–608, 612, 631–632, 650–651, 669–670, 702–703, 743–744, 827–841, 869–871, 917–920
   general.py89891%22–25, 139, 203, 313–314, 324
   model_method.py2667771%28–30, 198–201, 204–211, 303–304, 324, 345–364, 380–406, 409–426, 780, 791, 833–840, 878, 897, 977, 1034, 1109, 1223
   model_system.py2612292%43–45, 520–523, 570–577, 751–752, 974–978, 984–985, 993–994, 999, 1022
   numerical_settings.py2676277%30–32, 235, 237–238, 241–244, 248–249, 256–259, 268–271, 275–278, 280–283, 288–291, 297–300, 487–514, 589, 624–627, 651, 654, 699, 701–704, 708, 712, 759, 763–784, 839–840, 907, 990
   outputs.py1201092%27–28, 268–271, 311–314, 339, 341, 378, 397
   physical_property.py102793%38–40, 220, 349–351
   variables.py861286%26–28, 116, 139, 163, 185, 207, 229, 251, 274, 294
src/nomad_simulations/schema_packages/properties
   band_gap.py51590%26–28, 153–154
   band_structure.py1232580%27–29, 250–283, 296, 303, 339–340, 343, 390–391, 396
   energies.py42979%25–27, 54, 75, 100, 121, 137, 152
   fermi_surface.py17476%25–27, 58
   forces.py25676%26–28, 62, 82, 105
   greens_function.py991387%25–27, 228–229, 232, 253–254, 257, 278–279, 282, 418
   hopping_matrix.py29583%25–27, 76, 112
   permittivity.py48883%25–27, 115–123
   spectral_profile.py26012851%27–29, 75–78, 113–116, 217–318, 374–386, 411–414, 434, 439–442, 484–520, 544, 591–594, 610–611, 616–622
   thermodynamics.py752764%25–27, 53, 74, 90, 99, 108, 119, 128, 155, 165, 175, 190–192, 195, 211, 231–233, 236, 252, 272–274, 277
src/nomad_simulations/schema_packages/utils
   utils.py681479%26–29, 79–88, 97–98, 103, 106
TOTAL278355680% 

Tests Skipped Failures Errors Time
396 0 💤 1 ❌ 0 🔥 6.061s ⏱️

Please sign in to comment.