source: src/Potentials/unittests/PartialNucleiChargeFitterUnitTest.cpp@ d33f24

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_StructOpt_integration_tests Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion GeometryObjects Gui_displays_atomic_force_velocity IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps Ubuntu_1604_changes stable
Last change on this file since d33f24 was 58fcbe5, checked in by Frederik Heber <heber@…>, 11 years ago

Added functor for fitting partial nuclear charges.

  • is simply via solving the over-determined linear system of equations.
  • added unit test.
  • added basic idea to documentation.
  • has a masking threshold to leave out spheres around nuclei from fit.
  • Property mode set to 100644
File size: 3.7 KB
RevLine 
[58fcbe5]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2013 Frederik Heber. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * PartialNucleiChargeFitterUnitTest.cpp
25 *
26 * Created on: May 12, 2013
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35using namespace std;
36
37#include <cppunit/CompilerOutputter.h>
38#include <cppunit/extensions/TestFactoryRegistry.h>
39#include <cppunit/ui/text/TestRunner.h>
40
41#include "PartialNucleiChargeFitterUnitTest.hpp"
42
43#include <boost/assign.hpp>
44#include <vector>
45
46#include "CodePatterns/Assert.hpp"
47#include "LinearAlgebra/MatrixContent.hpp"
48#include "LinearAlgebra/Vector.hpp"
49
50#include "Fragmentation/Summation/SetValues/SamplingGrid.hpp"
51#include "Potentials/PartialNucleiChargeFitter.hpp"
52
53using namespace boost::assign;
54
55#ifdef HAVE_TESTRUNNER
56#include "UnitTestMain.hpp"
57#endif /*HAVE_TESTRUNNER*/
58
59/********************************************** Test classes **************************************/
60
61#define NUMBEROFSAMPLES(n) (size_t)(pow(pow(2,n),3))
62#define DOMAINVOLUME(l) (size_t)pow(l,3)
63
64// Registers the fixture into the 'registry'
65CPPUNIT_TEST_SUITE_REGISTRATION( PartialNucleiChargeFitterTest );
66
67
68void PartialNucleiChargeFitterTest::setUp()
69{
70 // failing asserts should be thrown
71 ASSERT_DO(Assert::Throw);
72
73 // create the grid with domain [0:1]^3
74 const double begin[3] = { 0., 0., 0. };
75 const double end[3] = { 1., 1., 1. };
76 SamplingGrid::sampledvalues_t values;
77 for (size_t i=0; i< DOMAINVOLUME(1)*NUMBEROFSAMPLES(2); ++i)
78 values += 0.;
79 SamplingGrid grid(begin, end, 2, values);
80
81 // create position(s) in center of domain
82 PartialNucleiChargeFitter::positions_t positions(1, Vector(.5,.5,.5));
83 fitter = new PartialNucleiChargeFitter(grid, positions);
84}
85
86
87void PartialNucleiChargeFitterTest::tearDown()
88{
89 delete fitter;
90}
91
92/** UnitTest for constructMatrix()
93 */
94void PartialNucleiChargeFitterTest::constructMatrixTest()
95{
96 // construct potential
97 MatrixContent testMatrix(DOMAINVOLUME(1)*NUMBEROFSAMPLES(2), 1);
98 Vector center(.5,.5,.5);
99 const double delta = 1./pow(2,2);
100 Vector N;
101 size_t index=0;
102 for(N[0]=0.; N[0] < 1.; N[0]+=delta)
103 for(N[1]=0.; N[1] < 1.; N[1]+=delta)
104 for(N[2]=0.; N[2] < 1.; N[2]+=delta) {
105 const double distance = N.distance(center);
106 if (fabs(distance) > std::numeric_limits<double>::epsilon()*1e4 )
107 testMatrix.at(index++, 0) = 1./(distance);
108 else
109 testMatrix.at(index++, 0) = 0.;
110 }
111
112 // check whether potential matrix is fine
113 fitter->constructMatrix();
114 const MatrixContent &ProblemMatrix = fitter->getMatrix();
115 CPPUNIT_ASSERT_EQUAL( testMatrix, ProblemMatrix );
116}
117
118/** UnitTest for operator()
119 */
120void PartialNucleiChargeFitterTest::operatorTest()
121{
122 // solution is zero everywhere
123 PartialNucleiChargeFitter::charges_t charges(1, 0.);
124
125 // true solution is ...
126 (*fitter)();
127 PartialNucleiChargeFitter::charges_t return_charges = fitter->getSolutionAsCharges_t();
128 CPPUNIT_ASSERT_EQUAL(charges, return_charges);
129}
Note: See TracBrowser for help on using the repository browser.