MDStressLab++
Loading...
Searching...
No Matches
main.cpp
Go to the documentation of this file.
1/*
2 * main.cpp
3 *
4 * Created on: Nov 3, 2019
5 * Author: Nikhil Admal
6 */
7#include "MethodSphere.h"
8#include <string>
9#include <iostream>
10#include <tuple>
11#include <fstream>
12#include "BoxConfiguration.h"
13#include "calculateStress.h"
14#include "Grid.h"
15#include "typedef.h"
16#include "kim_query.cpp"
17#include <regex>
18
19
20int main()
21{
23 std::vector<std::string> modelnames={
24 "Tersoff_LAMMPS_Tersoff_1988T3_Si__MO_186459956893_004"
25 };
26
27 std::cout << "Querying models." << std::endl;
28 for (int i = 0; i < modelnames.size(); ++i) {
29 std::cout << "Model: " << modelnames[i] << std::endl;
30 std::regex rgx("MO_\\d+_\\d{3}");
31
32 std::smatch match;
33 if (!std::regex_search(modelnames[i], match, rgx))
34 std::cout << "Regex error!" << std::endl;
35
36
37 std::string latticeConstant= kim_query(
38 "get_lattice_constant_cubic",
39 {
40 "model=[\"" + match.str()+ "\"]",
41 "crystal=[\"diamond\"]",
42 "species=[\"Si\"]",
43 "units=[\"angstrom\"]"
44 }
45 );
46 std::cout << "Lattice constant = " << latticeConstant << std::endl;
47 std::string elasticConstants= kim_query(
48 "get_elastic_constants_isothermal_cubic",
49 {
50 "model=[\"" + match.str()+ "\"]",
51 "crystal=[\"diamond\"]",
52 "species=[\"Si\"]",
53 "units=[\"eV/angstrom^3\"]"
54 }
55 );
56 std::cout << "Elastic constants = " << elasticConstants << std::endl;
57 std::cout << "------------------------------------------ " << std::endl;
58 }
62 int numberOfParticles;
63 int referenceAndFinal= true;
64 std::string configFileName= "config.data";
65 std::ifstream file(configFileName);
66 if(!file) MY_ERROR("ERROR: config.dat could not be opened for reading!");
67
68 file >> numberOfParticles;
69 if (numberOfParticles < 0) MY_ERROR("Error: Negative number of particles.\n");
70
71 BoxConfiguration body{numberOfParticles,referenceAndFinal};
72 body.read(configFileName,referenceAndFinal);
76 int ngrid;
77 ngrid= 90601;
78 Grid<Current> gridFromFile(ngrid);
79 gridFromFile.read("grid_cauchy.data");
83 MethodSphere hardy(6,"hardy");
84 for (const auto modelname : modelnames)
85 {
86 Kim kim(modelname);
87 try {
88 Stress<MethodSphere,Cauchy> hardyStress(hardy,&gridFromFile);
89
90 calculateStress(body, kim,
91 std::tie(),
92 std::tie(hardyStress), true);
93 hardyStress.write("project_hardy_" + modelname);
94 }
95 catch(const std::runtime_error& e){
96 std::cout << e.what() << std::endl;
97 std::cout << "Compute stress with projected forces failed. Moving on" << std::endl;
98 }
99
100 try{
101 Stress<MethodSphere,Cauchy> hardyStress(hardy,&gridFromFile);
102
103 // Calculate stress using the process_dedr, if possible
104 calculateStress(body, kim,
105 std::tie(),
106 std::tie(hardyStress));
107 hardyStress.write("hardy_" + modelname);
108 }
109 catch(const std::runtime_error& e){
110 std::cout << e.what() << std::endl;
111 std::cout << "Compute stress with process_dedr failed. Moving on" << std::endl;
112 }
113 }
116 return 0;
117}
118
119
int calculateStress(const BoxConfiguration &body, Kim &kim, std::tuple<> stress, const bool &projectForces=false)
Represents a particle configuration including simulation box information.
void read(std::string configFileName, int referenceAndFinal)
A function to read the properties of atoms from a file in a MDStressLab format.
Definition Grid.h:31
void read(std::string)
Definition Grid.cpp:133
Definition kim.h:21
Implements radially symmetric weighting functions (Hardy, Virial) and its associated bond function fo...
void write()
Definition Stress.h:90
std::string kim_query(const std::string &query_function, const std::initializer_list< std::string > &extra_args={ "species=[]", })
Definition kim_query.cpp:22
int main()
#define MY_ERROR(message)
Definition typedef.h:17