3 #include "LatticeParser.h"
5 LatticeParser::LatticeParser(const char *ini_file
)
6 : _ini(false, true, false)
8 SI_Error rc
= _ini
.LoadFile(ini_file
);
10 throw runtime_error("Failed loading structure ini file: " +
11 CSimpleIni::str_SI_Error(rc
));
14 const CSimpleIni::TKeyVal
*section
= _ini
.GetSection("UnitCell");
16 throw runtime_error("Ini file is missing 'UnitCell' section.");
19 #define ASSIGN_KEY(key_name, name) \
20 tmp = _ini.GetValue("UnitCell", key_name); \
22 throw runtime_error("UnitCell definition is missing " \
24 int name = atoi(tmp); \
26 ASSIGN_KEY("UnitCellSizeX", UnitCellSizeX);
27 ASSIGN_KEY("UnitCellSizeY", UnitCellSizeY
);
28 ASSIGN_KEY("GranularityX", GranularityX
);
29 ASSIGN_KEY("GranularityY", GranularityY
);
32 if (UnitCellSizeX
< 1 || UnitCellSizeY
< 1 || GranularityX
< 1 || GranularityY
< 1)
33 throw runtime_error("Unit cell has unreasonable size.");
35 _lattice
= new Lattice(UnitCellSizeX
, UnitCellSizeY
, GranularityX
, GranularityY
);
37 section
= _ini
.GetSection("Surface");
39 throw runtime_error("Ini file is missing 'Surface' section. ");
41 CSimpleIni::TNamesDepend Pd_positions
;
42 _ini
.GetAllValues("Surface", "Pd", Pd_positions
);
43 for (CSimpleIni::TNamesDepend::const_iterator i
= Pd_positions
.begin();
44 i
!= Pd_positions
.end(); ++i
) {
45 double x_frac
, y_frac
;
46 if (sscanf(i
->pItem
, "%lf/%lf", &x_frac
, &y_frac
) != 2 ||
47 x_frac
< 0 || x_frac
>= 1 ||
48 y_frac
< 0 || y_frac
>= 1)
49 throw runtime_error("Skrewed coordinates in " +
51 _lattice
->surface((int)(_lattice
->UnitCellSizeX
* x_frac
* _lattice
->GranularityX
),
52 (int)(_lattice
->UnitCellSizeY
* y_frac
* _lattice
->GranularityY
)) = Pd
;
56 section
= _ini
.GetSection("Adsorbates");
58 throw runtime_error("Ini file is missing 'Adsorbates' section. ");
60 CSimpleIni::TNamesDepend CO_positions
;
61 _ini
.GetAllValues("Adsorbates", "CO", CO_positions
);
62 for (CSimpleIni::TNamesDepend::const_iterator i
= CO_positions
.begin();
63 i
!= CO_positions
.end(); ++i
) {
64 double x_frac
, y_frac
;
65 if (sscanf(i
->pItem
, "%lf/%lf", &x_frac
, &y_frac
) != 2 ||
66 x_frac
< 0 || x_frac
>= 1 ||
67 y_frac
< 0 || y_frac
>= 1)
68 throw runtime_error("Skrewed coordinates in " +
70 _lattice
->adsorbates((int)(_lattice
->UnitCellSizeX
* x_frac
* _lattice
->GranularityX
),
71 (int)(_lattice
->UnitCellSizeY
* y_frac
* _lattice
->GranularityY
)) = CO
;
75 // Parse Symmetry options
76 CSimpleIni::TNamesDepend Symmetry_Operations
;
77 _ini
.GetAllValues("Symmetry", "Sym_Operation", Symmetry_Operations
);
78 for (CSimpleIni::TNamesDepend::const_iterator i
= Symmetry_Operations
.begin();
79 i
!= Symmetry_Operations
.end(); ++i
) {
80 double x_frac
, y_frac
;
81 if (sscanf(i
->pItem
, "%lf/%lf", &x_frac
, &y_frac
) != 2)
82 throw runtime_error("Skrewed coordinates in " +
84 _lattice
->_symmetryOperations
.directions
.push_back(Direction(x_frac
, y_frac
));
88 Lattice
*LatticeParser::getLattice()