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.");
18 #define ASSIGN_KEY(key_name, key_member) \
20 const char *tmp = _ini.GetValue("UnitCell", key_name); \
22 throw runtime_error("UnitCell definition is missing " \
24 _lattice.key_member = atoi(tmp); \
27 ASSIGN_KEY("SizeX", UnitCellSizeX
);
28 ASSIGN_KEY("SizeY", UnitCellSizeY
);
29 ASSIGN_KEY("Longitude", Longitude
);
30 ASSIGN_KEY("Latitude", Latitude
);
33 if (_lattice
.UnitCellSizeX
< 1 || _lattice
.UnitCellSizeY
< 1 ||
34 _lattice
.Longitude
< 1 || _lattice
.Latitude
< 1)
35 throw runtime_error("Unit cell has unreasonable size.");
37 _lattice
.adsorbates
.resize(_lattice
.Longitude
* _lattice
.UnitCellSizeX
+ 1,
38 _lattice
.Latitude
* _lattice
.UnitCellSizeY
+ 1);
39 _lattice
.adsorbates
= empty
;
40 _lattice
.surface
.resize(_lattice
.adsorbates
.shape());
41 _lattice
.surface
= empty
;
43 section
= _ini
.GetSection("Surface");
45 throw runtime_error("Ini file is missing 'Surface' section. "
46 "Maybe meaningful??");
48 CSimpleIni::TNamesDepend Pd_positions
;
49 _ini
.GetAllValues("Surface", "Pd", Pd_positions
);
50 for (CSimpleIni::TNamesDepend::const_iterator i
= Pd_positions
.begin();
51 i
!= Pd_positions
.end(); ++i
) {
52 double x_frac
, y_frac
;
53 if (sscanf(i
->pItem
, "%lf/%lf", &x_frac
, &y_frac
) != 2 ||
54 x_frac
< 0 || x_frac
>= 1 ||
55 y_frac
< 0 || y_frac
>= 1)
56 throw runtime_error("Skrewed coordinates in " +
58 _lattice
.surface((int)(_lattice
.UnitCellSizeX
* x_frac
),
59 (int)(_lattice
.UnitCellSizeY
* y_frac
)) = Pd
;
63 section
= _ini
.GetSection("Adsorbates");
65 throw runtime_error("Ini file is missing 'Adsorbates' section. "
66 "Maybe meaningful??");
68 CSimpleIni::TNamesDepend CO_positions
;
69 _ini
.GetAllValues("Adsorbates", "CO", CO_positions
);
70 for (CSimpleIni::TNamesDepend::const_iterator i
= CO_positions
.begin();
71 i
!= CO_positions
.end(); ++i
) {
72 double x_frac
, y_frac
;
73 if (sscanf(i
->pItem
, "%lf/%lf", &x_frac
, &y_frac
) != 2 ||
74 x_frac
< 0 || x_frac
>= 1 ||
75 y_frac
< 0 || y_frac
>= 1)
76 throw runtime_error("Skrewed coordinates in " +
78 _lattice
.adsorbates((int)(_lattice
.UnitCellSizeX
* x_frac
),
79 (int)(_lattice
.UnitCellSizeY
* y_frac
)) = CO
;
82 _lattice
.extendUnitCell();
85 Lattice
LatticeParser::getLattice()