[d76ce74] | 1 | /*
|
---|
| 2 | * Project: MoleCuilder
|
---|
| 3 | * Description: creates and alters molecular systems
|
---|
| 4 | * Copyright (C) 2012 University of Bonn. All rights reserved.
|
---|
[060e1e] | 5 | * Copyright (C) 2013 Frederik Heber. All rights reserved.
|
---|
[d76ce74] | 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>
|
---|
[931077] | 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>
|
---|
[d76ce74] | 48 |
|
---|
| 49 | #include "CodePatterns/Singleton_impl.hpp"
|
---|
| 50 |
|
---|
| 51 | #include "Potentials/SerializablePotential.hpp"
|
---|
[060e1e] | 52 |
|
---|
| 53 | #include "AllPotentialHeaders.hpp"
|
---|
[d76ce74] | 54 |
|
---|
[931077] | 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 |
|
---|
[d76ce74] | 71 | // static defines
|
---|
| 72 | PotentialFactory::NameToType_t PotentialFactory::NameToType =
|
---|
| 73 | boost::assign::map_list_of
|
---|
[931077] | 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
|
---|
[d76ce74] | 81 | ;
|
---|
| 82 | PotentialFactory::TypeToName_t PotentialFactory::TypeToName =
|
---|
| 83 | boost::assign::map_list_of
|
---|
[931077] | 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
|
---|
[d76ce74] | 91 | ;
|
---|
| 92 |
|
---|
[931077] | 93 | #undef sequence_print
|
---|
| 94 | #undef reverse_sequence_print
|
---|
| 95 |
|
---|
| 96 | #include "Potentials/Specifics/PotentialTypes.undef"
|
---|
[d76ce74] | 97 |
|
---|
[f6abb1] | 98 | enum PotentialTypes PotentialFactory::getTypeForName(const std::string &_name)
|
---|
| 99 | {
|
---|
| 100 | ASSERT (NameToType.count(_name),
|
---|
| 101 | "PotentialFactory::getTypeForName() - cannot find potential of name "+_name);
|
---|
| 102 | return NameToType[_name];
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | const std::string & PotentialFactory::getNameForType(enum PotentialTypes _type)
|
---|
| 106 | {
|
---|
| 107 | ASSERT (TypeToName.count(_type),
|
---|
| 108 | "PotentialFactory::getNameForType() - cannot find potential of name "+_type);
|
---|
| 109 | return TypeToName[_type];
|
---|
| 110 | }
|
---|
| 111 |
|
---|
[fdd23a] | 112 | EmpiricalPotential *PotentialFactory::createInstance(
|
---|
[d76ce74] | 113 | const std::string &potentialtype,
|
---|
[035c0d] | 114 | const SerializablePotential::ParticleTypes_t &types) const
|
---|
[d76ce74] | 115 | {
|
---|
[f6abb1] | 116 | switch (getTypeForName(potentialtype)) {
|
---|
[8203ce8] | 117 | case constant:
|
---|
| 118 | return new ConstantPotential(types);
|
---|
[d76ce74] | 119 | case tersoff:
|
---|
| 120 | return new ManyBodyPotential_Tersoff(types);
|
---|
| 121 | case morse:
|
---|
| 122 | return new PairPotential_Morse(types);
|
---|
[ff90e3] | 123 | case harmonic_bond:
|
---|
[d76ce74] | 124 | return new PairPotential_Harmonic(types);
|
---|
| 125 | case harmonic_angle:
|
---|
[484e2a] | 126 | return new ThreeBodyPotential_Angle(types);
|
---|
[1413f4] | 127 | case lennardjones:
|
---|
| 128 | return new PairPotential_LennardJones(types);
|
---|
[e2037e] | 129 | case torsion:
|
---|
| 130 | return new FourBodyPotential_Torsion(types);
|
---|
[791a12] | 131 | case improper:
|
---|
| 132 | return new FourBodyPotential_Improper(types);
|
---|
[d76ce74] | 133 | default:
|
---|
| 134 | ASSERT(0, "PotentialFactory::createInstance() - unknown potential desired to create.");
|
---|
| 135 | }
|
---|
| 136 | return NULL;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[f6abb1] | 139 | EmpiricalPotential* PotentialFactory::getDefaultPotential(const std::string &_name) const
|
---|
[b3b31e] | 140 | {
|
---|
| 141 | EmpiricalPotential *potential = NULL;
|
---|
[f6abb1] | 142 | switch (getTypeForName(_name)) {
|
---|
[b3b31e] | 143 | case constant:
|
---|
| 144 | potential = new ConstantPotential();
|
---|
| 145 | break;
|
---|
| 146 | case tersoff:
|
---|
| 147 | potential = new ManyBodyPotential_Tersoff();
|
---|
| 148 | break;
|
---|
| 149 | case morse:
|
---|
| 150 | potential = new PairPotential_Morse();
|
---|
| 151 | break;
|
---|
[ff90e3] | 152 | case harmonic_bond:
|
---|
[b3b31e] | 153 | potential = new PairPotential_Harmonic();
|
---|
| 154 | break;
|
---|
| 155 | case harmonic_angle:
|
---|
[484e2a] | 156 | potential = new ThreeBodyPotential_Angle();
|
---|
[b3b31e] | 157 | break;
|
---|
[1413f4] | 158 | case lennardjones:
|
---|
| 159 | potential = new PairPotential_LennardJones();
|
---|
| 160 | break;
|
---|
[e2037e] | 161 | case torsion:
|
---|
| 162 | potential = new FourBodyPotential_Torsion();
|
---|
| 163 | break;
|
---|
[791a12] | 164 | case improper:
|
---|
| 165 | potential = new FourBodyPotential_Improper();
|
---|
| 166 | break;
|
---|
[b3b31e] | 167 | default:
|
---|
| 168 | ASSERT(0, "PotentialFactory::createInstance() - unknown potential desired to create.");
|
---|
| 169 | break;
|
---|
| 170 | }
|
---|
| 171 | return potential;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
[d76ce74] | 174 | CONSTRUCT_SINGLETON(PotentialFactory)
|
---|