Commit 65cd002e authored by Jan Oliver Oelerich's avatar Jan Oliver Oelerich

Added possibility to use custom slice index in the crystal file.

parent bed4f227
......@@ -15,7 +15,9 @@ The crystal file is expected to be in `XYZ format <https://en.wikipedia.org/wiki
1. The **first line** contains the number of atoms.
2. The **second line** contains the cell dimension in x,y,z direction as floating point numbers in units of ``nm``,
separated by a space.
separated by a space. Optionally, it can contain the x, y, z dimensions in the .exyz format: ::
Lattice="lx 0.0 0.0 0.0 ly 0.0 0.0 0.0 lz"
3. The atomic information is given from the **third line onwards**, with each line corresponding to a single atom. Each
line must have *exactly 5 columns*:
......@@ -23,10 +25,9 @@ The crystal file is expected to be in `XYZ format <https://en.wikipedia.org/wiki
- The atomic species as elemental abbreviation (e.g., ``Ga`` for gallium)
- the x,y,z coordinates as floating point numbers in units of ``nm``
- the mean square displacement for the frozen lattice dislocations in units of :math:`nm^2`.
- (**optional**) The id of the slice this atom belongs to. This can be used to do custom slicing.
Below is a very brief, artificial example:
::
Below is a very brief, artificial example (without custom slicing): ::
5
1.0 2.0 10.0
......
......@@ -42,6 +42,7 @@ void stemsalabim::Crystal::init(const std::string &crystal_file_content) {
string line = "";
vector<string> tokens;
double x, y, z, msd;
unsigned int slice = 0;
// the first line is only the number of atoms.
getline(iss, line);
......@@ -82,7 +83,7 @@ void stemsalabim::Crystal::init(const std::string &crystal_file_content) {
}
atomic::Scattering & sf = atomic::Scattering::getInstance();
atomic::Scattering &sf = atomic::Scattering::getInstance();
// the rest of the lines is atoms with positions
size_t atom_id = 0;
......@@ -92,16 +93,23 @@ void stemsalabim::Crystal::init(const std::string &crystal_file_content) {
tokens = algorithms::split(line, ' ');
if(tokens.size() != 5) {
output::error("Init file needs to have 5 columns!\n");
if(tokens.size() != 5 && tokens.size() != 6) {
output::error("Init file needs to have 5 or 6 columns!\n");
}
bool with_slices = (tokens.size() == 6);
algorithms::trim(tokens[0]);
algorithms::trim(tokens[1]);
algorithms::trim(tokens[2]);
algorithms::trim(tokens[3]);
algorithms::trim(tokens[4]);
if(with_slices) {
algorithms::trim(tokens[5]);
slice = std::stoi(tokens[5]);
}
// x y z are columns 1,2,3 and the mean square displacement is column 4. Convert to angstrom
x = std::stod(tokens[1]) * 10;
y = std::stod(tokens[2]) * 10;
......@@ -109,7 +117,23 @@ void stemsalabim::Crystal::init(const std::string &crystal_file_content) {
msd = std::stod(tokens[4]) * 100;
// set the site's occupant
_atoms.push_back(std::make_shared<atomic::Atom>(x, y, z, msd, p.elementBySymbol(tokens[0]), atom_id));
if(with_slices) {
_atoms.push_back(shared_ptr<atomic::Atom>(new atomic::Atom(x,
y,
z,
msd,
p.elementBySymbol(tokens[0]),
atom_id,
slice)));
} else {
_atoms.push_back(shared_ptr<atomic::Atom>(new atomic::Atom(x,
y,
z,
msd,
p.elementBySymbol(tokens[0]),
atom_id)));
}
_elements.insert(p.elementBySymbol(tokens[0]));
sf.initPotential(p.elementBySymbol(tokens[0]));
......@@ -121,7 +145,6 @@ void stemsalabim::Crystal::init(const std::string &crystal_file_content) {
}
void stemsalabim::Crystal::readFieldFile(const std::string &field_file_content) {
// some useful variable declarations
......@@ -180,7 +203,6 @@ void stemsalabim::Crystal::generateSlices() {
}
void Crystal::assignFieldsToSlices() {
for(shared_ptr<Slice> &slic: _slices)
......
......@@ -62,9 +62,13 @@ void FPConfManager::assignAtomsToSlices() {
size_t i = 0;
for(shared_ptr<atomic::Atom> a: _crystal->getAtoms()) {
// should be improved
double z = a->getZ() + dz(i);
unsigned int slice_index = _crystal->sliceIndex(z);
unsigned int slice_index;
if(a->hasSlice())
slice_index = a->getSlice();
else {
double z = a->getZ() + dz(i);
slice_index = _crystal->sliceIndex(z);
}
_crystal->slices()[slice_index]->addAtom(a);
......
......@@ -23,6 +23,7 @@
#define STEMSALABIM_ATOM_HPP
#include <utility>
#include "Element.hpp"
namespace stemsalabim { namespace atomic {
......@@ -53,12 +54,33 @@ namespace stemsalabim { namespace atomic {
: _x(x)
, _y(y)
, _z(z)
, _element(el)
, _element(std::move(el))
, _msd(msd)
, _id(id) {
};
/*!
* Constructor with initial values
* @param x x coordinate of the atom
* @param y y coordinate of the atom
* @param z z coordinate of the atom
* @param msd mean square displacement in the Einstein solid of the atom
* @param el the Element type
* @param id some identifier
*/
Atom(double x, double y, double z, double msd, std::shared_ptr<Element> el, size_t id, unsigned int slice)
: _x(x)
, _y(y)
, _z(z)
, _element(std::move(el))
, _msd(msd)
, _id(id)
, _slice(slice)
, _has_slice(true) {
};
/*!
* Get the x coordinate
* @return x coordinate of the atom
......@@ -99,6 +121,22 @@ namespace stemsalabim { namespace atomic {
return _id;
}
/*!
* Get the custom slice of the atom
* @return id
*/
unsigned int getSlice() const {
return _slice;
}
/*!
* true if has custom slice
* @return true if custom slice
*/
bool hasSlice() const {
return _has_slice;
}
/*!
* Get the element of the atom
* @return element
......@@ -114,6 +152,8 @@ namespace stemsalabim { namespace atomic {
std::shared_ptr<Element> _element;
double _msd;
size_t _id;
unsigned int _slice{0};
bool _has_slice{false};
};
}}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment