Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:ComputationalPhysics/atomify-lammps
Browse files Browse the repository at this point in the history
into dev
  • Loading branch information
dragly committed Aug 15, 2016
2 parents 0835c50 + fac7b80 commit ccc4dfa
Show file tree
Hide file tree
Showing 22 changed files with 731 additions and 473 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "SimVis"]
path = SimVis
url = https://github.com/ComputationalPhysics/SimVis.git
[submodule "atomify-lammps/QMLPlot"]
path = atomify-lammps/QMLPlot
url = https://github.com/andeplane/QMLPlot.git
2 changes: 1 addition & 1 deletion SimVis
31 changes: 18 additions & 13 deletions atomify-lammps/LammpsWrappers/atoms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,32 +135,37 @@ void Atoms::synchronize(LAMMPSController *lammpsController)

void Atoms::updateData(System *system, LAMMPS *lammps)
{
AtomData atomData = m_atomData;
if(!atomData.isValid()) {
m_atomDataProcessed = m_atomData;
// AtomData atomData = m_atomData;
if(!m_atomDataProcessed.isValid()) {
qDebug() << "Atom data is not valid before modifiers.";
exit(1);
}

for(QVariant &modifier_ : m_modifiers) {
Modifier *modifier = modifier_.value<Modifier*>();
modifier->setSystem(system);
modifier->apply(atomData);
if(!atomData.isValid()) {
modifier->apply(m_atomDataProcessed);
if(!m_atomDataProcessed.isValid()) {
// TODO: insert modifier name to debug message
qDebug() << "Atom data is not valid after modifier.";
exit(1);
}
}

if(m_sort) {
QElapsedTimer t;
t.start();
m_atomData.sort(system->cameraPosition());
qDebug() << "Sorted using " << t.elapsed() << " ms.";
}
// if(m_sort) {
// QElapsedTimer t;
// t.start();
// m_atomData.sort(system->cameraPosition());
// qDebug() << "Sorted using " << t.elapsed() << " ms.";
// }
// generateBondData(m_atomDataProcessed, *system);
// generateSphereData(m_atomDataProcessed);
}

generateBondData(atomData, *system);
generateSphereData(atomData);
void Atoms::synchronizeRenderer() {
generateBondData(m_atomDataProcessed);
generateSphereData(m_atomDataProcessed);
}

//void Atoms::findOcclusion(AtomData &atomData) {
Expand Down Expand Up @@ -191,7 +196,7 @@ void Atoms::generateSphereData(AtomData &atomData) {
m_sphereData->setData(atomData.positions, atomData.colors, atomData.radii);
}

void Atoms::generateBondData(AtomData &atomData, System &system) {
void Atoms::generateBondData(AtomData &atomData) {
bondsDataRaw.resize(0);
if(!m_bonds->enabled()) {
m_bondData->setData(bondsDataRaw);
Expand Down
4 changes: 3 additions & 1 deletion atomify-lammps/LammpsWrappers/atoms.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Atoms : public QObject
float bondRadius() const;
void reset();
bool sort() const;
void synchronizeRenderer();

public slots:
void setBondRadius(float bondRadius);
Expand All @@ -61,6 +62,7 @@ public slots:

private:
AtomData m_atomData;
AtomData m_atomDataProcessed;
QVector<BondVBOData> bondsDataRaw;
QMap<QString, AtomStyle*> m_atomStyleTypes;
QVector<AtomStyle*> m_atomStyles;
Expand All @@ -69,7 +71,7 @@ public slots:
class Bonds* m_bonds = nullptr;
QVariantList m_modifiers;
float m_bondRadius = 0.1;
void generateBondData(AtomData &atomData, System &system);
void generateBondData(AtomData &atomData);
void generateBondDataFromLammpsNeighborlist(AtomData &atomData, LAMMPS_NS::LAMMPS &lammps);
void generateSphereData(AtomData &atomData);
bool m_sort = false;
Expand Down
2 changes: 1 addition & 1 deletion atomify-lammps/LammpsWrappers/bonds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void Bonds::reset()
}
}

m_enabled = true;
m_enabled = false;
}

void Bonds::setEnabled(bool enabled)
Expand Down
20 changes: 18 additions & 2 deletions atomify-lammps/LammpsWrappers/computes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,30 @@ void Computes::synchronize(LAMMPSController *lammpsController)
removeCompute(compute->identifier());
}

setCount(m_data.size());
setModel(QVariant::fromValue(m_data));
for(QObject *obj : m_data) {
CPCompute *compute = qobject_cast<CPCompute*>(obj);
for(QVariant &variant : compute->data1D()) {
CP1DData *data = variant.value<CP1DData *>();
emit data->updated();
}
}

if(!lammpsController->state.canProcessSimulatorControls) return;
for(QObject *object : m_data) {
CPCompute *compute = qobject_cast<CPCompute*>(object);
compute->copyData(lammpsController);
}

setCount(m_data.size());
setModel(QVariant::fromValue(m_data));
}

void Computes::computeAll(LAMMPSController *lammpsController)
{
for(QObject *object : m_data) {
CPCompute *compute = qobject_cast<CPCompute*>(object);
compute->computeInLAMMPS(lammpsController);
}
}

int Computes::count() const
Expand Down
1 change: 1 addition & 0 deletions atomify-lammps/LammpsWrappers/computes.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class Computes : public QObject
public:
explicit Computes(QObject *parent = 0);
void synchronize(class LAMMPSController *lammpsController);
void computeAll(class LAMMPSController *lammpsController);
void reset();
int count() const;
QVariant model() const;
Expand Down
103 changes: 63 additions & 40 deletions atomify-lammps/LammpsWrappers/simulatorcontrols/cpcompute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ CP1DData *CPCompute::ensureExists(QString key, bool enabledByDefault) {

bool CPCompute::copyData(ComputeTemp *compute, LAMMPSController *lammpsController) {
if(!compute) return false;
double value = compute->compute_scalar();
double value = compute->scalar;
setHasScalarData(true);
setScalarValue(value);
CP1DData *data = ensureExists(QString("Temperature"), true);
Expand All @@ -38,7 +38,7 @@ bool CPCompute::copyData(ComputeTemp *compute, LAMMPSController *lammpsControlle
bool CPCompute::copyData(ComputePE *compute, LAMMPSController *lammpsController) {
if(!compute) return false;
if(lammpsController->lammps()->update->ntimestep != lammpsController->lammps()->update->eflag_global) return true;
double value = compute->compute_scalar();
double value = compute->scalar;
setHasScalarData(true);
setScalarValue(value);
CP1DData *data = ensureExists(QString("Potential energy"), true);
Expand All @@ -50,7 +50,7 @@ bool CPCompute::copyData(ComputePE *compute, LAMMPSController *lammpsController)

bool CPCompute::copyData(ComputeKE *compute, LAMMPSController *lammpsController) {
if(!compute) return false;
double value = compute->compute_scalar();
double value = compute->scalar;
setHasScalarData(true);
setScalarValue(value);
CP1DData *data = ensureExists(QString("Kinetic energy"), true);
Expand All @@ -66,7 +66,7 @@ bool CPCompute::copyData(ComputePressure *compute, LAMMPSController *lammpsContr
if(!virialComputed) return true;

// First compute scalar pressure
double value = compute->compute_scalar();
double value = compute->scalar;
setHasScalarData(true);
setScalarValue(value);
CP1DData *data = ensureExists(QString("Pressure"), true);
Expand All @@ -75,7 +75,7 @@ bool CPCompute::copyData(ComputePressure *compute, LAMMPSController *lammpsContr
data->add(lammpsController->system()->simulationTime(), value);

// Then compute stress tensor
compute->compute_vector();
// compute->compute_vector();
// xx, yy, zz, xy, xz, yz
QStringList components = {"xx", "yy", "zz", "xy", "xz", "yz"};

Expand All @@ -92,7 +92,7 @@ bool CPCompute::copyData(ComputePressure *compute, LAMMPSController *lammpsContr
bool CPCompute::copyData(ComputeRDF *compute, LAMMPSController *lammpsController) {
Q_UNUSED(lammpsController);
if(!compute) return false;
compute->compute_array();
// compute->compute_array();
int numBins = compute->size_array_rows; // rows in global array
int numColumns = compute->size_array_cols; // columns in global array
int numPairs = (numColumns - 1)/2;
Expand All @@ -107,15 +107,18 @@ bool CPCompute::copyData(ComputeRDF *compute, LAMMPSController *lammpsController
double rdf = compute->array[bin][1+2*pairId];
data->add(r,rdf,true);
}

emit data->updated();
}



return true;
}

bool CPCompute::copyData(ComputeMSD *compute, LAMMPSController *lammpsController) {
if(!compute) return false;
compute->compute_vector();
// compute->compute_vector();

// http://www.ascii.cl/htmlcodes.htm
QStringList components = {"∆x<sup>2</sup>", "∆y<sup>2</sup>", "∆z<sup>2</sup>", "∆r<sup>2</sup>"};
Expand All @@ -133,7 +136,7 @@ bool CPCompute::copyData(ComputeMSD *compute, LAMMPSController *lammpsController

bool CPCompute::copyData(ComputeVACF *compute, LAMMPSController *lammpsController) {
if(!compute) return false;
compute->compute_vector();
// compute->compute_vector();

// &lt; because < is used as a html tag. Using HTML names instead: http://www.ascii.cl/htmlcodes.htm
QStringList components = {"&lt;vx, vx0\&gt;", "&lt;vy, vy0&gt;", "&lt;vz, vz0&gt;", "&lt;v, v0&gt;"};
Expand All @@ -151,7 +154,7 @@ bool CPCompute::copyData(ComputeVACF *compute, LAMMPSController *lammpsControlle

bool CPCompute::copyData(ComputeCOM *compute, LAMMPSController *lammpsController) {
if(!compute) return false;
compute->compute_vector();
// compute->compute_vector();

// &lt; because < is used as a html tag. Using HTML names instead: http://www.ascii.cl/htmlcodes.htm
QStringList components = {"x_cm", "y_cm", "z_cm"};
Expand All @@ -171,15 +174,15 @@ bool CPCompute::copyData(ComputeGyration *compute, LAMMPSController *lammpsContr
if(!compute) return false;

// First compute scalar Rg
double value = compute->compute_scalar();
double value = compute->scalar;
setHasScalarData(true);
setScalarValue(value);
CP1DData *data = ensureExists(QString("Radius of gyration"), true);
setXLabel("Time");
setYLabel("Pressure");
data->add(lammpsController->system()->simulationTime(), value);

compute->compute_vector();
// compute->compute_vector();

// &lt; because < is used as a html tag. Using HTML names instead: http://www.ascii.cl/htmlcodes.htm
QStringList components = {"xx", "yy", "zz", "xy", "xz", "yz"};
Expand All @@ -195,22 +198,41 @@ bool CPCompute::copyData(ComputeGyration *compute, LAMMPSController *lammpsContr
return true;
}

bool CPCompute::copyData(ComputeChunkAtom *compute, LAMMPSController *lammpsController) {
if(!compute) return false;

enum{BIN1D,BIN2D,BIN3D,BINSPHERE,BINCYLINDER,
TYPE,MOLECULE,COMPUTE,FIX,VARIABLE};
enum{LOWER,CENTER,UPPER,COORD};
enum{BOX,LATTICE,REDUCED};
enum{NODISCARD,MIXED,YESDISCARD};
enum{ONCE,NFREQ,EVERY}; // used in several files
enum{LIMITMAX,LIMITEXACT};
void CPCompute::computeInLAMMPS(LAMMPSController *lammpsController) {
Compute *compute = lammpsController->findComputeByIdentifier(identifier());
if(compute->scalar_flag == 1) {
try {
compute->compute_scalar();
} catch (LammpsException &exception) {
// TODO: handle this better than just ignoring exception.

if(compute->which == BIN2D) {
// qDebug() << "ERROR: LAMMPS threw an exception!";
// qDebug() << "ERROR: File:" << QString::fromStdString(exception.file());
// qDebug() << "ERROR: Message:" << QString::fromStdString(exception.error());
}
}

if(compute->vector_flag == 1) {
try {
compute->compute_scalar();
} catch (LammpsException &exception) {
// TODO: handle this better than just ignoring exception.
// qDebug() << "ERROR: LAMMPS threw an exception!";
// qDebug() << "ERROR: File:" << QString::fromStdString(exception.file());
// qDebug() << "ERROR: Message:" << QString::fromStdString(exception.error());
}
}

return true;
if(compute->array_flag == 1) {
try {
compute->compute_array();
} catch (LammpsException &exception) {
// TODO: handle this better than just ignoring exception.
// qDebug() << "ERROR: LAMMPS threw an exception!";
// qDebug() << "ERROR: File:" << QString::fromStdString(exception.file());
// qDebug() << "ERROR: Message:" << QString::fromStdString(exception.error());
}
}
}

void CPCompute::copyData(LAMMPSController *lammpsController)
Expand All @@ -220,25 +242,29 @@ void CPCompute::copyData(LAMMPSController *lammpsController)
// if(lammpsController->system()->timesteps() % m_frequency != 0) return;
Compute *lmp_compute = lammpsController->findComputeByIdentifier(identifier());
if(lmp_compute == nullptr) return;

if(copyData(dynamic_cast<ComputePressure*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeTemp*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeKE*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputePE*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeRDF*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeMSD*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeVACF*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeCOM*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeGyration*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeChunkAtom*>(lmp_compute), lammpsController)) return;

try {
if(copyData(dynamic_cast<ComputePressure*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeTemp*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeKE*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputePE*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeRDF*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeMSD*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeVACF*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeCOM*>(lmp_compute), lammpsController)) return;
if(copyData(dynamic_cast<ComputeGyration*>(lmp_compute), lammpsController)) return;
} catch (LammpsException &exception) {
qDebug() << "ERROR: LAMMPS threw an exception!";
qDebug() << "ERROR: File:" << QString::fromStdString(exception.file());
qDebug() << "ERROR: Message:" << QString::fromStdString(exception.error());
return;
}
if(lmp_compute->scalar_flag == 1) {
try {
double value = lmp_compute->compute_scalar();
setHasScalarData(true);
setScalarValue(value);
CP1DData *data = ensureExists("scalar", true);
data->add(lammpsController->system()->simulationTime(), value);
data->add(lammpsController->system()->simulationTime(), value, true);
} catch (LammpsException &exception) {
qDebug() << "ERROR: LAMMPS threw an exception!";
qDebug() << "ERROR: File:" << QString::fromStdString(exception.file());
Expand All @@ -253,17 +279,14 @@ void CPCompute::copyData(LAMMPSController *lammpsController)
QString key = QString("%1").arg(i);
CP1DData *data = ensureExists(key, true);
double value = lmp_compute->vector[i-1];
data->add(lammpsController->system()->simulationTime(), value);
data->add(lammpsController->system()->simulationTime(), value, true);
}
} catch (LammpsException &exception) {
qDebug() << "ERROR: LAMMPS threw an exception!";
qDebug() << "ERROR: File:" << QString::fromStdString(exception.file());
qDebug() << "ERROR: Message:" << QString::fromStdString(exception.error());
}
}
if(lmp_compute->array_flag == 1) {

}
}

void CPCompute::updateCommand()
Expand Down
4 changes: 2 additions & 2 deletions atomify-lammps/LammpsWrappers/simulatorcontrols/cpcompute.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class CPCompute : public SimulatorControl
~CPCompute();
void copyData(LAMMPSController *lammpsController);
bool existsInLammps(LAMMPSController *lammpsController) override;
void computeInLAMMPS(LAMMPSController *lammpsController);
bool isVector() const;
QString group() const;
int frequency() const;
Expand Down Expand Up @@ -80,13 +81,12 @@ public slots:
bool copyData(ComputeVACF *compute, LAMMPSController *lammpsController);
bool copyData(ComputeCOM *compute, LAMMPSController *lammpsController);
bool copyData(ComputeGyration *compute, LAMMPSController *lammpsController);
bool copyData(ComputeChunkAtom *compute, LAMMPSController *lammpsController);
CP1DData *ensureExists(QString key, bool enabledByDefault);

bool m_isVector = false;
double m_time = 0;
QString m_group = "all";
int m_frequency = 2;
int m_frequency = 10;
bool m_hasScalarData = false;
float m_scalarValue = 0.0;
int m_num1DData = 0;
Expand Down
Loading

0 comments on commit ccc4dfa

Please sign in to comment.