2 #include "StringTokenizer.h"
8 #include "StructureParser.h"
10 StructureParser::StructureParser(const char *ini_file_interactions
,
11 const char *ini_file_structure
) :
12 _ini_structure(false, true, false) {
13 _structure
= new Structure();
14 cout
<< "parsing lattice" << endl
;
15 LatticeParser
latticeParser(ini_file_structure
);
16 _structure
->lattice
= latticeParser
.getLattice();
17 cout
<< "printing lattice: " << endl
;
18 cout
<< *_structure
->lattice
;
20 cout
<< "parsing interactions" << endl
;
21 InteractionsParser
interactionsParser(ini_file_interactions
);
22 _structure
->interactions
= interactionsParser
.getInteractions();
24 //cout << "before symmetrizing" << _structure->interactions << endl;
26 // Generate Symmetryequivalent Interactions
27 _structure
->interactions
.symmetrizeInteractions(_structure
->interactions
);
29 //cout << "interactions before joining double name occurencies " << endl << _structure->interactions << endl;
31 // join symmetry equivalent representations of multi body interactions as given in input file by same name
32 _structure
->interactions
.joinSymmetryEquivalent(_structure
->interactions
);
34 //cout << "interactions (before assessment):" << endl << _structure->interactions << endl;
35 _structure
->lattice
->assessInteractions(_structure
->interactions
);
36 cout
<< "interactions (after assessment):" << endl
<< _structure
->interactions
;
38 // Parse Structure Energetics
39 SI_Error rc
= _ini_structure
.LoadFile(ini_file_structure
);
41 throw runtime_error("Failed loading structure ini file: "
42 + CSimpleIni::str_SI_Error(rc
));
44 double energy_value
= 0.0;
45 CSimpleIni::TNamesDepend energies
;
46 _ini_structure
.GetAllKeys("OnSiteEnergies", energies
);
47 for (CSimpleIni::TNamesDepend::const_iterator i
= energies
.begin(); i
48 != energies
.end(); ++i
) {
49 CSimpleIni::TNamesDepend values
;
50 _ini_structure
.GetAllValues("OnSiteEnergies", i
->pItem
, values
);
51 for (CSimpleIni::TNamesDepend::const_iterator k
= values
.begin(); k
52 != values
.end(); ++k
) {
54 StringTokenizer strtok
= StringTokenizer(k
->pItem
, ",");
55 int cnt
= strtok
.countTokens();
57 throw runtime_error("Empty \"" + string(k
->pItem
) + "\" key.");
58 for (int i
= 0; i
< cnt
; i
++) {
59 string tmp
= strtok
.nextToken();
60 if (sscanf(tmp
.c_str(), "%lf", &energy_value
) != 1) {
61 // Treat last tuple as Occupation specifier
66 "On Site Energy definition is wrong in: "
71 // FIXME : checking for different adsorbate species, defined by name, FIX: onSite energy is given as sum of all species here!
72 _structure
->onSiteEnergy
= energy_value
;
75 CSimpleIni::TNamesDepend dft_energies
;
76 if (!(_ini_structure
.GetAllValues("DFT_Energy", "E0", dft_energies
)))
77 _structure
->newStructure
= true;
79 double dft_energy
= 0.0;
80 for (CSimpleIni::TNamesDepend::const_iterator l
= dft_energies
.begin(); l
81 != dft_energies
.end(); ++l
) {
82 if (sscanf(l
->pItem
, "%lf", &dft_energy
) != 1)
83 throw runtime_error("DFT Energy definition is wrong in: "
85 _structure
->dftEnergy
= dft_energy
;
90 Structure
*StructureParser::getStructure() {