1 // -*- C++ -*-
2 //
3 // asap_kim_api.h: Common interfaces classes for Asap potentials in OpenKIM.
4 //
5 // Copyright (C) 2012-2013 Jakob Schiotz and the Department of Physics,
6 // Technical University of Denmark.  Email: schiotz@fysik.dtu.dk
7 //
8 // This file is part of Asap version 3.
9 // Asap is released under the GNU Lesser Public License (LGPL) version 3.
10 // However, the parts of Asap distributed within the OpenKIM project
11 // (including this file) are also released under the Common Development
12 // and Distribution License (CDDL) version 1.0.
13 //
14 // This program is free software: you can redistribute it and/or
15 // modify it under the terms of the GNU Lesser General Public License
16 // version 3 as published by the Free Software Foundation.  Permission
17 // to use other versions of the GNU Lesser General Public License may
18 // granted by Jakob Schiotz or the head of department of the
19 // Department of Physics, Technical University of Denmark, as
20 // described in section 14 of the GNU General Public License.
21 //
22 // This program is distributed in the hope that it will be useful,
23 // but WITHOUT ANY WARRANTY; without even the implied warranty of
24 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25 // GNU General Public License for more details.
26 //
27 // You should have received a copy of the GNU General Public License
28 // and the GNU Lesser Public License along with this program.  If not,
29 // see <http://www.gnu.org/licenses/>.
30 
31 
32 #ifndef ASAP_KIM_API_H
33 #define ASAP_KIM_API_H
34 
35 #include "KimAtoms.h"
36 #include "NeighborLocator.h"
37 
38 namespace ASAPSPACE {
39 
40 class Potential;
41 
42 class PotentialKimMixin
43 {
44 public:
45   // PotentialKimMixin() {};
46 
47   virtual int ComputeArgumentsCreate(
48     KIM::ModelComputeArgumentsCreate * const modelComputeArgumentsCreate) const = 0;
49 
50   // Per default, no ComputeArgumentsDestroy is needed.
ComputeArgumentsDestroy(KIM::ModelComputeArgumentsDestroy * const modelComputeArgumentsDestroy)51   virtual int ComputeArgumentsDestroy(
52     KIM::ModelComputeArgumentsDestroy * const modelComputeArgumentsDestroy) const {return 0;}
53 };
54 
55 // AsapKimPotential is the main object that KIM interfaces with.  It
56 // delegates almost everything to the actual potential, which is both
57 // an instance of an asap Potential and an instance of
58 // PotentialKimMixin (multiple inheritance!).
59 class AsapKimPotential
60 {
61 public:
62   AsapKimPotential(KIM::ModelDriverCreate * const modelDriverCreate,
63 		   bool supportvirial);
64   virtual ~AsapKimPotential();
65 
66   // Set the potential, it must be both a Potential and a PotentialKimMixin.
67   void SetPotential(Potential *pot);
68 
69   static int compute_static(void *km);
70   int compute(void *km);
71 
72   PyAsap_NeighborLocatorObject *CreateNeighborList(KimAtoms *atoms,
73                                                    double cutoff,
74                                                    double drift);
75 
76 private:
77 
78   int Compute(KIM::ModelCompute const * const modelCompute,
79               KIM::ModelComputeArguments const * const modelComputeArguments);
80 
81   // The following member functions are static, they are called as
82   // functions (not methods of an instance) to set up the API,
83   // information about the instance actually being set up is extracted
84   // from the first argument.
85   static int ComputeArgumentsCreate(
86     KIM::ModelCompute const * const modelCompute,
87     KIM::ModelComputeArgumentsCreate * const modelComputeArgumentsCreate);
88 
89   static int ComputeArgumentsDestroy(
90     KIM::ModelCompute const * const modelCompute,
91     KIM::ModelComputeArgumentsDestroy * const modelComputeArgumentsDestroy);
92 
93   static int Destroy(KIM::ModelDestroy * const modelDestroy);
94 
95   static int Compute_static(KIM::ModelCompute const * const modelCompute,
96 			    KIM::ModelComputeArguments const * const modelComputeArguments);
97 
98 
99 
100 public:
101   vector<string> paramfile_names;   // The original parameter file name list.  Possibly used by reinit.
102   bool supportvirial;      // This potential supports virials.
103 
104 private:
105   //Data
106   Potential *potential;    // The ASAP potential being used
107   PotentialKimMixin *potential_as_kimmixin;   // Same potential, different interface.
108   KimAtoms *atoms;
109   bool need_contrib;
110   const char *NBCstr;   // Neighbor list string, kept for error messages.
111 };
112 
113 } // end namespace
114 
115 #endif // not ASAP_KIM_API_H
116