source: src/Potentials/PotentialFactory.cpp@ e2037e

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing 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_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions 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 FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since e2037e was e2037e, checked in by Frederik Heber <heber@…>, 11 years ago

Added FourBodyPotential_Torsion.

  • also added regression test to torsion potential.
  • Property mode set to 100644
File size: 5.0 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2012 University of Bonn. All rights reserved.
5 * Copyright (C) 2013 Frederik Heber. All rights reserved.
6 * Please see the COPYING file or "Copyright notice" in builder.cpp for details.
7 *
8 *
9 * This file is part of MoleCuilder.
10 *
11 * MoleCuilder is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * MoleCuilder is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
23 */
24
25/*
26 * PotentialFactory.cpp
27 *
28 * Created on: 30.11.2012
29 * Author: heber
30 */
31
32// include config.h
33#ifdef HAVE_CONFIG_H
34#include <config.h>
35#endif
36
37#include "CodePatterns/MemDebug.hpp"
38
39#include "PotentialFactory.hpp"
40
41#include <boost/assign/list_of.hpp>
42#include <boost/lambda/lambda.hpp>
43#include <boost/preprocessor/seq/elem.hpp>
44#include <boost/preprocessor/seq/seq.hpp>
45#include <boost/preprocessor/seq/size.hpp>
46#include <boost/preprocessor/stringize.hpp>
47#include <boost/preprocessor/iteration/local.hpp>
48
49#include "CodePatterns/Singleton_impl.hpp"
50
51#include "Potentials/SerializablePotential.hpp"
52
53#include "AllPotentialHeaders.hpp"
54
55#include "Potentials/Specifics/PotentialTypes.def"
56
57//!> function to print each member of the sequence in the enumeration
58#define sequence_print(z,n,seq) \
59 ( \
60 BOOST_PP_STRINGIZE( BOOST_PP_SEQ_ELEM(n, seq) ), \
61 BOOST_PP_SEQ_ELEM(n, seq) \
62 )
63
64//!> function to print each member of the sequence in the enumeration
65#define reverse_sequence_print(z,n,seq) \
66 ( \
67 BOOST_PP_SEQ_ELEM(n, seq), \
68 BOOST_PP_STRINGIZE( BOOST_PP_SEQ_ELEM(n, seq) ) \
69 )
70
71// static defines
72PotentialFactory::NameToType_t PotentialFactory::NameToType =
73 boost::assign::map_list_of
74#if defined PotentialTypes_END // do we have parameters at all?
75#define BOOST_PP_LOCAL_MACRO(n) sequence_print(~, n, POTENTIALSEQUENCE)
76#define BOOST_PP_LOCAL_LIMITS (0, PotentialTypes_END-1)
77#include BOOST_PP_LOCAL_ITERATE()
78#undef BOOST_PP_LOCAL_MACRO
79#undef BOOST_PP_LOCAL_LIMITS
80#endif
81 ;
82PotentialFactory::TypeToName_t PotentialFactory::TypeToName =
83 boost::assign::map_list_of
84#if defined PotentialTypes_END // do we have parameters at all?
85#define BOOST_PP_LOCAL_MACRO(n) reverse_sequence_print(~, n, POTENTIALSEQUENCE)
86#define BOOST_PP_LOCAL_LIMITS (0, PotentialTypes_END-1)
87#include BOOST_PP_LOCAL_ITERATE()
88#undef BOOST_PP_LOCAL_MACRO
89#undef BOOST_PP_LOCAL_LIMITS
90#endif
91 ;
92
93#undef sequence_print
94#undef reverse_sequence_print
95
96#include "Potentials/Specifics/PotentialTypes.undef"
97
98EmpiricalPotential *PotentialFactory::createInstance(
99 const std::string &potentialtype,
100 const SerializablePotential::ParticleTypes_t &types) const
101{
102 ASSERT (NameToType.count(potentialtype),
103 "PotentialFactory::createInstance() - cannot find potential of name "+potentialtype);
104 switch (NameToType[potentialtype]) {
105 case constant:
106 return new ConstantPotential(types);
107 case tersoff:
108 return new ManyBodyPotential_Tersoff(types);
109 case morse:
110 return new PairPotential_Morse(types);
111 case harmonic:
112 return new PairPotential_Harmonic(types);
113 case harmonic_angle:
114 return new ThreeBodyPotential_Angle(types);
115 case lennardjones:
116 return new PairPotential_LennardJones(types);
117 case torsion:
118 return new FourBodyPotential_Torsion(types);
119 default:
120 ASSERT(0, "PotentialFactory::createInstance() - unknown potential desired to create.");
121 }
122 return NULL;
123}
124
125EmpiricalPotential *PotentialFactory::createInstance(
126 const std::string &potentialtype,
127 std::istream &serialized) const
128{
129 EmpiricalPotential *potential = NULL;
130 ASSERT (NameToType.count(potentialtype),
131 "PotentialFactory::createInstance() - cannot find potential of name "+potentialtype);
132 switch (NameToType[potentialtype]) {
133 case constant:
134 potential = new ConstantPotential();
135 break;
136 case tersoff:
137 potential = new ManyBodyPotential_Tersoff();
138 break;
139 case morse:
140 potential = new PairPotential_Morse();
141 break;
142 case harmonic:
143 potential = new PairPotential_Harmonic();
144 break;
145 case harmonic_angle:
146 potential = new ThreeBodyPotential_Angle();
147 break;
148 case lennardjones:
149 potential = new PairPotential_LennardJones();
150 break;
151 case torsion:
152 potential = new FourBodyPotential_Torsion();
153 break;
154 default:
155 ASSERT(0, "PotentialFactory::createInstance() - unknown potential desired to create.");
156 break;
157 }
158 // now stream in types and parameters
159 potential->stream_from(serialized);
160
161 return potential;
162}
163
164CONSTRUCT_SINGLETON(PotentialFactory)
Note: See TracBrowser for help on using the repository browser.