atomicrex  0.1
An advanced atomistic model building tool
PairPotential.h
1 //
3 // Copyright (C) 2017, Alexander Stukowski and Paul Erhart
4 //
5 // This file is part of atomicrex.
6 //
7 // Atomicrex is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Atomicrex is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //
21 
22 #pragma once
23 
24 #include "Potential.h"
25 #include "functions/Functions.h"
26 
27 namespace atomicrex {
28 
29 /************************************************************
30  * A pair-wise interaction between two atom types A and B, which
31  * is defined by an arbitrary one-dimensional function V_ab(r).
32  ************************************************************/
33 class PairInteraction : public FitObject
34 {
35 public:
36 
38  PairInteraction(const FPString& id, FitJob* job, int atomTypeA, int atomTypeB, const std::shared_ptr<FunctionBase>& V, const FPString& tag = FPString())
39  : FitObject(id, job, tag), _atomTypeA(atomTypeA), _atomTypeB(atomTypeB), _V(V)
40  {
41  registerSubObject(V.get());
42  }
43 
45  int atomTypeA() const { return _atomTypeA; }
46  int atomTypeB() const { return _atomTypeB; }
47 
49  bool interacting(int type_i, int type_j) const {
50  if(type_i == _atomTypeA && type_j == _atomTypeB) return true;
51  if(type_i == _atomTypeB && type_j == _atomTypeA) return true;
52  return false;
53  }
54 
56  bool isActive(int type) const {
57  if(type == _atomTypeA || type == _atomTypeB) return true;
58  return false;
59  }
60 
62  const std::shared_ptr<FunctionBase>& V() const { return _V; };
63 
64 private:
65 
68  int _atomTypeA, _atomTypeB;
69 
71  std::shared_ptr<FunctionBase> _V;
72 };
73 
74 /************************************************************
75  * Generic interatomic pair potential.
76  ************************************************************/
77 class PairPotential : public Potential
78 {
79 public:
80 
82  PairPotential(const FPString& id, FitJob* job) : Potential(id, job, "Pair") {}
83 
85  virtual double cutoff() const override { return _cutoff; }
86 
88  virtual double computeEnergy(AtomicStructure& structure, NeighborList& neighborList) override;
89 
91  virtual double computeEnergyAndForces(AtomicStructure& structure, NeighborList& neighborList) override;
92 
94  virtual void outputResults() override;
95 
97  void writePotential(const FPString& filename) const;
98 
100  void writeTables(const FPString& basename) const;
101 
102 public:
103 
104  // Functions that parse XML elements in job file.
105  void parse(XML::Element potentialElement) override;
106  void parseInteractions(XML::Element parentElement);
107 
110  virtual XML::OElement generateXMLDefinition() override;
111 
112 private:
113 
115  double _cutoff;
116 
118  std::vector< std::shared_ptr<PairInteraction> > _pairInteractions;
119 
121  FPString _exportPotentialFile;
122 
124  FPString _exportFunctionsFile;
125 };
126 
127 } // End of namespace
Base class for maintaining structures.
Definition: AtomicStructure.h:42
virtual void parse(XML::Element element)
Parses the base parameters, common to structures, groups, and potentials, from the XML element in the...
Definition: FitObject.cpp:149
Definition: NeighborList.h:58
void registerSubObject(FitObject *subobject, bool deleteOnShutdown=false)
Registers a sub-object.
Definition: FitObject.cpp:57
Definition: PairPotential.h:33
const FPString & tag() const
Returns the assigned tag string.
Definition: FitObject.h:144
bool isActive(int type) const
Returns whether the interaction contains the geiven atom type.
Definition: PairPotential.h:56
const std::shared_ptr< FunctionBase > & V() const
Returns the pair potential function.
Definition: PairPotential.h:62
This file collects the definition of classes that define various simple crystal structures.
Definition: Atomicrex.h:67
virtual double cutoff() const override
Returns the maximum cutoff of the potential.
Definition: PairPotential.h:85
Definition: PairPotential.h:77
bool interacting(int type_i, int type_j) const
Returns whether the interaction between the two given atom types is described by this pair interactio...
Definition: PairPotential.h:49
std::string FPString
The default string type used throughout the code:
Definition: Atomicrex.h:70
Definition: XMLUtilities.h:226
Definition: XMLUtilities.h:69
Definition: FitObject.h:42
Definition: FitJob.h:37
FitJob * job() const
Returns a pointer to the job to which this object belongs.
Definition: FitObject.h:150
int atomTypeA() const
Returns the atom type indices whose interaction is described by this object.
Definition: PairPotential.h:45
PairInteraction(const FPString &id, FitJob *job, int atomTypeA, int atomTypeB, const std::shared_ptr< FunctionBase > &V, const FPString &tag=FPString())
Constructor.
Definition: PairPotential.h:38
PairPotential(const FPString &id, FitJob *job)
Constructor.
Definition: PairPotential.h:82
Base class for potential.
Definition: Potential.h:41