n2p2 - A neural network potential package
ElementCabana.h
Go to the documentation of this file.
1// n2p2 - A neural network potential package
2// Copyright (C) 2018 Andreas Singraber (University of Vienna)
3// Copyright (C) 2020 Saaketh Desai and Sam Reeve
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <https://www.gnu.org/licenses/>.
17
18#ifndef ELEMENT_CABANA_H
19#define ELEMENT_CABANA_H
20
21#include "typesCabana.h"
22
23#include "CutoffFunction.h"
24#include "Element.h"
25#include "utility.h"
26
27#include <cstddef> // size_t
28#include <string> // string
29#include <vector> // vector
30
31namespace nnp
32{
33
35class ElementCabana : public Element
36{
37 public:
40 ElementCabana( std::size_t const index );
44
55 template <class t_SF, class h_t_int>
56 void addSymmetryFunction( std::string const &parameters,
57 std::vector<std::string> elementStrings,
58 int attype, t_SF SF, double convLength,
59 h_t_int h_numSFperElem );
64 void changeLengthUnitSymmetryFunctions( double convLength );
72 template <class t_SF, class h_t_int>
73 void sortSymmetryFunctions( t_SF SF, h_t_int h_numSFperElem, int attype );
81 template <class t_SF>
82 bool compareSF( t_SF SF, int attype, int index1, int index2 );
90 template <class t_SF, class h_t_int>
91 std::vector<std::string>
92 infoSymmetryFunctionParameters( t_SF SF, int attype,
93 h_t_int h_numSFperElem ) const;
104 template <class t_SF, class t_SFscaling, class h_t_int>
105 std::vector<std::string>
107 t_SF SF, t_SFscaling SFscaling,
108 int attype,
109 h_t_int h_numSFperElem ) const;
121 template <class t_SF, class t_SFGmemberlist, class h_t_int>
122 void setupSymmetryFunctionGroups( t_SF SF, t_SFGmemberlist SFGmemberlist,
123 int attype, h_t_int h_numSFperElem,
124 h_t_int h_numSFGperElem,
125 int maxSFperElem );
133 template <class t_SF, class t_SFGmemberlist, class h_t_int>
134 std::vector<std::string>
135 infoSymmetryFunctionGroups( t_SF SF, t_SFGmemberlist SFGmemberlist,
136 int attype, h_t_int h_numSFGperElem ) const;
146 template <class t_SF, class h_t_int>
147 void setCutoffFunction( CutoffFunction::CutoffType const cutoffType,
148 double const cutoffAlpha, t_SF SF, int attype,
149 h_t_int h_numSFperElem );
164 template <class t_SF, class t_SFscaling, class h_t_int>
165 void setScaling( ScalingType scalingType,
166 std::vector<std::string> const &statisticsLine,
167 double minS, double maxS, t_SF SF,
168 t_SFscaling SFscaling, int attype,
169 h_t_int h_numSFperElem ) const;
178 template <class h_t_int>
179 std::size_t numSymmetryFunctions( int attype, h_t_int h_numSFperElem ) const;
190 template <class t_SF>
191 std::size_t getMinNeighbors( int attype, t_SF SF, int nSF ) const;
201 template <class t_SF, class h_t_int>
202 double getMinCutoffRadius( t_SF SF, int attype,
203 h_t_int h_numSFperElem ) const;
213 template <class t_SF, class h_t_int>
214 double getMaxCutoffRadius( t_SF SF, int attype,
215 h_t_int h_numSFperElem ) const;
216
217 /* Update symmetry function statistics.
218 *
219 */
220 // void updateSymmetryFunctionStatistics(
221
223 // SymmetryFunctionStatistics statistics;
224
236 template <class t_SFscaling>
237 inline void setScalingType( ScalingType scalingType,
238 std::string statisticsLine,
239 double Smin, double Smax,
240 t_SFscaling SFscaling,
241 int attype, int k ) const;
250 template <class t_SFscaling>
251 inline std::string scalingLine( ScalingType scalingType,
252 t_SFscaling SFscaling,
253 int attype, int k ) const;
261 template <class t_SFscaling>
262 inline double unscale( int attype, double value, int k,
263 t_SFscaling SFscaling );
264
265 private:
266 using Element::index;
269 using Element::symbol;
270};
271
273// Inlined function definitions //
275
276template <class h_t_int>
277inline std::size_t
279 h_t_int h_numSFperElem ) const
280{
281 return h_numSFperElem( attype );
282}
283
284template <class t_SFscaling>
285inline void
287 std::string statisticsLine, double Smin,
288 double Smax, t_SFscaling SFscaling,
289 int attype, int k ) const
290{
291 double Gmin, Gmax, Gmean, Gsigma = 0, scalingFactor = 0;
292 std::vector<std::string> s = split( reduce( statisticsLine ) );
293
294 Gmin = atof( s.at( 2 ).c_str() );
295 Gmax = atof( s.at( 3 ).c_str() );
296 Gmean = atof( s.at( 4 ).c_str() );
297 SFscaling( attype, k, 0 ) = Gmin;
298 SFscaling( attype, k, 1 ) = Gmax;
299 SFscaling( attype, k, 2 ) = Gmean;
300
301 // Older versions may not supply sigma.
302 if ( s.size() > 5 )
303 Gsigma = atof( s.at( 5 ).c_str() );
304 SFscaling( attype, k, 3 ) = Gsigma;
305
306 SFscaling( attype, k, 4 ) = Smin;
307 SFscaling( attype, k, 5 ) = Smax;
308 SFscaling( attype, k, 7 ) = scalingType;
309
310 if ( scalingType == ST_NONE )
311 scalingFactor = 1.0;
312 else if ( scalingType == ST_SCALE )
313 scalingFactor = ( Smax - Smin ) / ( Gmax - Gmin );
314 else if ( scalingType == ST_CENTER )
315 scalingFactor = 1.0;
316 else if ( scalingType == ST_SCALECENTER )
317 scalingFactor = ( Smax - Smin ) / ( Gmax - Gmin );
318 else if ( scalingType == ST_SCALESIGMA )
319 scalingFactor = ( Smax - Smin ) / Gsigma;
320 SFscaling( attype, k, 6 ) = scalingFactor;
321
322 return;
323}
324
325template <class t_SFscaling>
326inline std::string
328 t_SFscaling SFscaling, int attype,
329 int k ) const
330{
331 return strpr( "%4zu %9.2E %9.2E %9.2E %9.2E %9.2E %5.2f %5.2f %d\n",
332 k + 1, SFscaling( attype, k, 0 ),
333 SFscaling( attype, k, 1 ), SFscaling( attype, k, 2 ),
334 SFscaling( attype, k, 3 ), SFscaling( attype, k, 6 ),
335 SFscaling( attype, k, 4 ), SFscaling( attype, k, 5 ),
336 scalingType );
337}
338
339template <class t_SFscaling>
340inline double ElementCabana::unscale( int attype, double value, int k,
341 t_SFscaling SFscaling )
342{
343 double scalingType = SFscaling( attype, k, 7 );
344 double scalingFactor = SFscaling( attype, k, 6 );
345 double Gmin = SFscaling( attype, k, 0 );
346 // double Gmax = SFscaling(attype,k,1);
347 double Gmean = SFscaling( attype, k, 2 );
348 // double Gsigma = SFscaling(attype,k,3);
349 double Smin = SFscaling( attype, k, 4 );
350 // double Smax = SFscaling(attype,k,5);
351
352 if ( scalingType == 0.0 )
353 {
354 return value;
355 }
356 else if ( scalingType == 1.0 )
357 {
358 return ( value - Smin ) / scalingFactor + Gmin;
359 }
360 else if ( scalingType == 2.0 )
361 {
362 return value + Gmean;
363 }
364 else if ( scalingType == 3.0 )
365 {
366 return ( value - Smin ) / scalingFactor + Gmean;
367 }
368 else if ( scalingType == 4.0 )
369 {
370 return ( value - Smin ) / scalingFactor + Gmean;
371 }
372 else
373 {
374 return 0.0;
375 }
376}
377
378}
379
380#include "ElementCabana_impl.h"
381
382#endif
CutoffType
List of available cutoff function types.
Derived Cabana class for element-specific data.
Definition: ElementCabana.h:36
void setScaling(ScalingType scalingType, std::vector< std::string > const &statisticsLine, double minS, double maxS, t_SF SF, t_SFscaling SFscaling, int attype, h_t_int h_numSFperElem) const
Set scaling of all symmetry functions.
~ElementCabana()
Destructor.
std::size_t getMinNeighbors(int attype, t_SF SF, int nSF) const
Get maximum of required minimum number of neighbors for all symmetry functions for this element.
void setScalingType(ScalingType scalingType, std::string statisticsLine, double Smin, double Smax, t_SFscaling SFscaling, int attype, int k) const
Symmetry function statistics.
void changeLengthUnitSymmetryFunctions(double convLength)
Change length unit for all symmetry functions.
std::size_t index
Global index of this element.
Definition: Element.h:255
void setCutoffFunction(CutoffFunction::CutoffType const cutoffType, double const cutoffAlpha, t_SF SF, int attype, h_t_int h_numSFperElem)
Set cutoff function for all symmetry functions.
bool compareSF(t_SF SF, int attype, int index1, int index2)
Print symmetry function parameter value information.
ElementCabana(std::size_t const index)
Constructor using index.
std::vector< std::string > infoSymmetryFunctionGroups(t_SF SF, t_SFGmemberlist SFGmemberlist, int attype, h_t_int h_numSFGperElem) const
Print symmetry function group info.
std::vector< std::string > infoSymmetryFunctionParameters(t_SF SF, int attype, h_t_int h_numSFperElem) const
Print symmetry function parameter value information.
std::vector< std::string > infoSymmetryFunctionScaling(ScalingType scalingType, t_SF SF, t_SFscaling SFscaling, int attype, h_t_int h_numSFperElem) const
Print symmetry function scaling information.
std::string scalingLine(ScalingType scalingType, t_SFscaling SFscaling, int attype, int k) const
Print scaling for one symmetry function.
double unscale(int attype, double value, int k, t_SFscaling SFscaling)
Unscale one symmetry function.
void addSymmetryFunction(std::string const &parameters, std::vector< std::string > elementStrings, int attype, t_SF SF, double convLength, h_t_int h_numSFperElem)
Add one symmetry function.
Contains element-specific data.
Definition: Element.h:39
void sortSymmetryFunctions()
Sort all symmetry function.
Definition: Element.cpp:154
double getMinCutoffRadius() const
Get minimum cutoff radius of all symmetry functions.
Definition: Element.cpp:397
void setupSymmetryFunctionGroups()
Set up symmetry function groups.
Definition: Element.cpp:194
std::size_t index
Global index of this element.
Definition: Element.h:255
std::string symbol
Element symbol.
Definition: Element.h:265
double atomicEnergyOffset
Offset energy for every atom of this element.
Definition: Element.h:259
double getMaxCutoffRadius() const
Get maximum cutoff radius of all symmetry functions.
Definition: Element.cpp:414
std::size_t numSymmetryFunctions() const
Get number of symmetry functions.
Definition: Element.h:353
std::size_t atomicNumber
Atomic number of this element.
Definition: Element.h:257
Definition: Atom.h:29
string strpr(const char *format,...)
String version of printf function.
Definition: utility.cpp:90
vector< string > split(string const &input, char delimiter)
Split string at each delimiter.
Definition: utility.cpp:33
string reduce(string const &line, string const &whitespace, string const &fill)
Replace multiple whitespaces with fill.
Definition: utility.cpp:60
ScalingType
Definition: typesCabana.h:26
@ ST_CENTER
Definition: typesCabana.h:29
@ ST_SCALE
Definition: typesCabana.h:28
@ ST_SCALECENTER
Definition: typesCabana.h:30
@ ST_NONE
Definition: typesCabana.h:27
@ ST_SCALESIGMA
Definition: typesCabana.h:31