Skip to content

Commit

Permalink
Activate LAMMMPS trajectory files (.lammpstrj)
Browse files Browse the repository at this point in the history
  • Loading branch information
Luthaf committed Mar 18, 2016
1 parent 186c978 commit 7237af1
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ set(VMD_MOLFILE_PLUGINS_ENABLED
molfiles/src/dcdplugin.c
molfiles/src/gromacsplugin.cxx
molfiles/src/pdbplugin.c
molfiles/src/lammpsplugin.c
)

# These plugins are not yet activated, but can be compiled into chemfiles easily
Expand Down Expand Up @@ -60,7 +61,6 @@ set(VMD_MOLFILE_PLUGINS_DISABLED
molfiles/src/grdplugin.cxx
molfiles/src/gridplugin.cxx
molfiles/src/jsplugin.c
molfiles/src/lammpsplugin.c
molfiles/src/maeffplugin.cxx
molfiles/src/mapplugin.cxx
molfiles/src/mdfplugin.cxx
Expand Down
1 change: 1 addition & 0 deletions include/chemfiles/formats/Molfile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum MolfileFormat {
TRR, ///< Gromacs .trr file format
XTC, ///< Gromacs .xtc file format
TRJ, ///< Gromacs .trj file format
LAMMPS, ///< Lammps trajectory files
};

//! A thin wrapper around the vmd plugin functions
Expand Down
1 change: 1 addition & 0 deletions src/TrajectoryFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ TrajectoryFactory::TrajectoryFactory() : formats_(), extensions_() {
registration<Molfile<TRR>>(formats_, extensions_);
registration<Molfile<XTC>>(formats_, extensions_);
registration<Molfile<TRJ>>(formats_, extensions_);
registration<Molfile<LAMMPS>>(formats_, extensions_);
}

TrajectoryFactory& TrajectoryFactory::get() {
Expand Down
5 changes: 4 additions & 1 deletion src/formats/Molfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ static std::map<MolfileFormat, plugin_data_t> molfile_plugins {
{TRR, {"TRR", "gromacsplugin", "trr", ".trr", true}},
{XTC, {"XTC", "gromacsplugin", "xtc", ".xtc", false}},
{TRJ, {"TRJ", "gromacsplugin", "trj", ".trj", true}},
{LAMMPS, {"LAMMPS", "lammpsplugin", "lammpstrj", ".lammpstrj", false}},
};

struct plugin_reginfo_t {
Expand Down Expand Up @@ -103,7 +104,7 @@ void Molfile<F>::read(Frame& frame){
std::vector<float> coords(3*static_cast<size_t>(natoms_));
std::vector<float> velocities(0);

molfile_timestep_t timestep;
molfile_timestep_t timestep{};
timestep.coords = coords.data();
if (molfile_plugins[F].have_velocities){
velocities.resize(3*static_cast<size_t>(natoms_));
Expand Down Expand Up @@ -254,6 +255,7 @@ namespace chemfiles {
PLUGINS_FUNCTIONS(gromacsplugin, TRR);
PLUGINS_FUNCTIONS(gromacsplugin, XTC);
PLUGINS_FUNCTIONS(gromacsplugin, TRJ);
PLUGINS_FUNCTIONS(lammpsplugin, LAMMPS);
}

#undef PLUGINS_FUNCTIONS
Expand All @@ -265,3 +267,4 @@ template class chemfiles::Molfile<GRO>;
template class chemfiles::Molfile<TRR>;
template class chemfiles::Molfile<XTC>;
template class chemfiles::Molfile<TRJ>;
template class chemfiles::Molfile<LAMMPS>;
2 changes: 1 addition & 1 deletion tests/data
Submodule data updated 1 files
+72,366 −0 lammps/polymer.lammpstrj
23 changes: 23 additions & 0 deletions tests/formats/lammps-molfile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "catch.hpp"
#include "chemfiles.hpp"
using namespace chemfiles;

#define LAMMPSDIR SRCDIR "/data/lammps/"

bool roughly(const Vector3D& a, const Vector3D& b, const double eps){
return (fabs(a[0] - b[0]) < eps)
&& (fabs(a[1] - b[1]) < eps)
&& (fabs(a[2] - b[2]) < eps);
}

TEST_CASE("Read files in LAMMPS .lammpstrj format using Molfile", "[Molfile]"){
Trajectory file(LAMMPSDIR "polymer.lammpstrj");
Frame frame = file.read();
double eps = 1e-3;

CHECK(frame.natoms() == 1714);
auto positions = frame.positions();
CHECK(roughly(positions[0], vector3d(51.8474f, 100.348f, 116.516f), eps));
// this one has a non zero image index (1 0 0)
CHECK(roughly(positions[1189], vector3d(116.829f, 91.2404f, 79.8858f), eps));
}

0 comments on commit 7237af1

Please sign in to comment.