Skip to content

Commit

Permalink
Merge pull request #142 from NWChemEx/deriv_ptypes
Browse files Browse the repository at this point in the history
Provisional Derivative Property Types
  • Loading branch information
jwaldrop107 authored Apr 23, 2024
2 parents 00df017 + b7881de commit e405abd
Show file tree
Hide file tree
Showing 6 changed files with 146 additions and 6 deletions.
41 changes: 41 additions & 0 deletions include/simde/derivative/nuclear.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,59 @@
#include <chemist/chemist.hpp>
#include <simde/derivative/derivative_pt.hpp>
#include <simde/energy/ao_energy.hpp>
#include <simde/energy/total_energy.hpp>

namespace simde {

/** @brief Property type which computes the derivative with respect to nuclear
* positions.
*
* @tparam PropertyType The property type we are taking the derivitive of.
* @tparam TensorType The type the gradient is returned as.
*/
template<typename PropertyType, typename TensorType>
using NuclearDerivative =
Derivative<PropertyType, chemist::PointSet<double>, TensorType>;

/** @brief Specializes NuclearDerivative to when PropertyType == TotalEnergy
*
* @tparam TensorType The type the gradient is returned as.
*/
template<typename TensorType>
using EnergyNuclearGradient = NuclearDerivative<TotalEnergy, TensorType>;

/** @brief Specializes NuclearDerivative to Hessians of TotalEnergy
*
* @tparam TensorType The type the Hessian is returned as.
*/
template<typename TensorType>
using EnergyNuclearHessian =
NuclearDerivative<EnergyNuclearGradient<TensorType>, TensorType>;

/** @brief Specializes NuclearDerivative to Gradients of AOEnergy
*
* @tparam TensorType The type of the gradient
*/
template<typename TensorType>
using AOEnergyNuclearGradient = NuclearDerivative<AOEnergy, TensorType>;

/** @brief Specializes NuclearDerivative to Hessians of AOEnergy
*
* @tparam TensorType The type of the gradient
*/
template<typename TensorType>
using AOEnergyNuclearHessian =
NuclearDerivative<AOEnergyNuclearGradient<TensorType>, TensorType>;

// -- Assumes tensors are stored as std::vector objects
using EnergyNuclearGradientStdVectorD =
EnergyNuclearGradient<std::vector<double>>;

using EnergyNuclearHessianStdVectorD =
EnergyNuclearHessian<std::vector<double>>;
using AOEnergyNuclearGradientStdVectorD =
AOEnergyNuclearGradient<std::vector<double>>;
using AOEnergyNuclearHessianStdVectorD =
AOEnergyNuclearHessian<std::vector<double>>;

} // namespace simde
31 changes: 31 additions & 0 deletions src/python/derivative/export_derivative.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/

#pragma once
#include "../export_simde.hpp"
#include <pluginplay/pluginplay.hpp>
#include <simde/derivative/derivative.hpp>

namespace simde {

inline void export_derivative(python_module_reference m) {
EXPORT_PROPERTY_TYPE(EnergyNuclearGradientStdVectorD, m);
EXPORT_PROPERTY_TYPE(EnergyNuclearHessianStdVectorD, m);
EXPORT_PROPERTY_TYPE(AOEnergyNuclearGradientStdVectorD, m);
EXPORT_PROPERTY_TYPE(AOEnergyNuclearHessianStdVectorD, m);
}

} // namespace simde
2 changes: 2 additions & 0 deletions src/python/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "basis_set/export_basis_set.hpp"
#include "chemical_system/export_chemical_system.hpp"
#include "derivative/export_derivative.hpp"
#include "energy/export_energy.hpp"
#include "export_simde.hpp"

Expand All @@ -27,6 +28,7 @@ PYBIND11_MODULE(simde, m) {
export_chemical_system(m);
export_basis_set(m);
export_energy(m);
export_derivative(m);
}

} // namespace simde
17 changes: 11 additions & 6 deletions tests/cxx/unit_tests/derivative/nuclear.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
#include <simde/energy/ao_energy.hpp>
#include <vector>

using Gradient = simde::AOEnergyNuclearGradient<std::vector<double>>;
using Hessian = simde::AOEnergyNuclearHessian<std::vector<double>>;
using Gradient = simde::EnergyNuclearGradientStdVectorD;
using Hessian = simde::EnergyNuclearHessianStdVectorD;
using AOGradient = simde::AOEnergyNuclearGradientStdVectorD;
using AOHessian = simde::AOEnergyNuclearHessianStdVectorD;

TEST_CASE("Nuclear Derivative Property Types") {
test_property_type<Gradient>({"AOs", "Chemical System", "Arg 1"},
{"Derivative"});

test_property_type<Hessian>({"AOs", "Chemical System", "Arg 1", "Arg 2"},
test_property_type<Gradient>({"Chemical System", "Arg 1"}, {"Derivative"});
test_property_type<Hessian>({"Chemical System", "Arg 1", "Arg2"},
{"Derivative"});
test_property_type<AOGradient>({"AOs", "Chemical System", "Arg 1"},
{"Derivative"});

test_property_type<AOHessian>({"AOs", "Chemical System", "Arg 1", "Arg 2"},
{"Derivative"});
}
13 changes: 13 additions & 0 deletions tests/python/unit_tests/derivative/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# 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.
48 changes: 48 additions & 0 deletions tests/python/unit_tests/derivative/test_derivative.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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 simde
from test_property_type import BaseTestPropertyType


class TestEnergyNuclearGradientStdVectorD(BaseTestPropertyType):

def setUp(self):
self.pt = simde.EnergyNuclearGradientStdVectorD()
self.input_labels = ["Chemical System", "Arg 1"]
self.result_labels = ["Derivative"]


class TestEnergyNuclearHessianStdVectorD(BaseTestPropertyType):

def setUp(self):
self.pt = simde.EnergyNuclearHessianStdVectorD()
self.input_labels = ["Chemical System", "Arg 1", "Arg 2"]
self.result_labels = ["Derivative"]


class TestAOEnergyNuclearGradientStdVectorD(BaseTestPropertyType):

def setUp(self):
self.pt = simde.AOEnergyNuclearGradientStdVectorD()
self.input_labels = ["AOs", "Chemical System", "Arg 1"]
self.result_labels = ["Derivative"]


class TestAOEnergyNuclearHessianStdVectorD(BaseTestPropertyType):

def setUp(self):
self.pt = simde.AOEnergyNuclearHessianStdVectorD()
self.input_labels = ["AOs", "Chemical System", "Arg 1", "Arg 2"]
self.result_labels = ["Derivative"]

0 comments on commit e405abd

Please sign in to comment.