1 // -*- C++ -*-
2 //
3 // KimNeighborLocator.h: Common base class for KIM interface neighbor locators.
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 
33 
34 #ifndef KIMNEIGHBORLOCATOR_H
35 #define KIMNEIGHBORLOCATOR_H
36 
37 #include "NeighborLocator.h"
38 
39 #define INVALIDMETHOD {throw AsapError("Invalid KimNeighborLocator method called.");}
40 
41 namespace ASAPSPACE {
42 
43 PyAsap_NeighborLocatorObject *PyAsap_NewKimNeighborLocator(KimAtoms *atoms,
44 							   double rCut);
45 
46 
47 class KimNeighborLocator : public NeighborLocator
48 {
49 public:
50   KimNeighborLocator(KimAtoms *atoms, double rCut);
51 
52   friend PyAsap_NeighborLocatorObject *PyAsap_NewKimNeighborLocator(KimAtoms *atoms,
53 								    double rCut);
54 
55   friend void PyAsap_Dealloc<PyAsap_NeighborLocatorObject>(PyObject *self);
56 
57 protected:
58   virtual ~KimNeighborLocator();
59 
60 public:
61   virtual string GetName() const INVALIDMETHOD;
62 
63   /// Check if the neighbor list can still be reused, update if not.
64   ///
65   /// KIM version: Call UpdateNeighborList and then return false.
CheckAndUpdateNeighborList()66   virtual bool CheckAndUpdateNeighborList() {return CheckNeighborList();}
67 
68   /// Check if the neighbor list can still be reused, update if not.
69   ///
70   /// This version is used when called from Python
CheckAndUpdateNeighborList(PyObject * atoms)71   virtual bool CheckAndUpdateNeighborList(PyObject *atoms) {return CheckNeighborList();}
72 
73   /// Check the neighbor list.
74   ///
75   /// Check if the neighbor list can still be reused, return true if
76   /// it should be updated.
77   ///
78   /// KIM version: Call UpdateNeigborList and then return false.
79 
80   virtual bool CheckNeighborList();
81 
82   /// Update neighbor list
83   ///
84   /// KIM version: Extract any necessary info from the API object.
UpdateNeighborList()85   virtual void UpdateNeighborList() {invalid = false;}  // Not much needed for this one.;
86 
87   /// Get wrapped positions of all the atoms
88   virtual const vector<Vec> &GetWrappedPositions() const INVALIDMETHOD
89 
90   virtual void GetWrappedPositions(vector<Vec> &wp) const INVALIDMETHOD;
91 
92   /// Get scaled positions of all the atoms
93   virtual const vector<Vec> &GetScaledPositions() const INVALIDMETHOD;
94 
95   /// Get info about the neighbors of atom n.  The most important method :-)
96   ///
97   /// Input values: n is the number of the atom.  r (optional) is a
98   /// cutoff, must be less than rCut in the constructor (not
99   /// checked!).
100   ///
101   /// In-out values: size contains the maximum space in the arrays.
102   /// It is decremented by the number of neighbors placed in the
103   /// arrays.  It is an error to call GetNeighbors with too small a
104   /// value of size.
105   ///
106   /// Out values: neighbors[] contains the numbers of the atoms,
107   /// diffs[] contains the \em relative positions of the atoms,
108   /// diffs2[] contains the norms of the diffs vectors.
109   ///
110   /// Return value: The number of neighbors.
111   virtual int GetNeighbors(int n, int *neighbors, Vec *diffs, double *diffs2,
112                            int& size, double r = -1.0) const
113     {throw AsapError("Trying to use an OpenKIM full neighbor list as a half list");}
114 
115   virtual int GetFullNeighbors(int n, int *neighbors, Vec *diffs, double *diffs2,
116                            int& size, double r = -1.0) const;
117 
118   /// Get the neighbors of atom n (half neighbor list).
119   ///
120   /// This version of GetNeighbors only returns the numbers of the neighbors.
121   /// It is intended for the Python interface.
122   virtual void GetNeighbors(int n, vector<int> &neighbors) const INVALIDMETHOD;
123 
124   /// Return the guaranteed maximal length of a single atom's NB list.
125 
126   /// Call this before using GetNeighbors() to make sure the arrays
127   /// are big enough.  The value may change when the neighbor list is
128   /// updated.
MaxNeighborListLength()129   virtual int MaxNeighborListLength() const {return 512;} // Compiled into API.
130 
131   /// Return the cutoff distance of this neighbor locator.
132   virtual double GetCutoffRadius() const INVALIDMETHOD;
133 
134   /// Return the cutoff distance including twice the drift.
135   virtual double GetCutoffRadiusWithDrift() const INVALIDMETHOD;
136 
137   /// Get the number of atoms in the corresponding list of atoms.
138   virtual int GetNumberOfAtoms() const INVALIDMETHOD;  // Used by the Python interface
139 
140   /// Return the atoms access object.  Used by a few tool functions.
141   virtual Atoms *GetAtoms() const INVALIDMETHOD;
142 
143   /// Print internal info about an atom
144   virtual void print_info(int n) INVALIDMETHOD;
145 
146   /// Print memory usage
147   virtual long PrintMemory() const INVALIDMETHOD;
148 
149 protected:  // Data
150   KimAtoms *atoms;
151   bool nbmode;
152   int nAtoms;
153   int nGhosts;
154   double rcut;
155   double rcut2;  // Square of cutoff
156 };
157 
158 } // end namespace
159 
160 #undef INVALIDMETHOD
161 #endif // !KIMNEIGHBORLOCATOR_H
162 
163