votca 2024.2-dev
Loading...
Searching...
No Matches
lammpsdumpwriter.cc
Go to the documentation of this file.
1/*
2 * Copyright 2009-2021 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18#include "lammpsdumpwriter.h"
19#include <cstdio>
20#include <string>
22
23namespace votca {
24namespace csg {
25
26using namespace std;
27using namespace votca::tools;
28
29void LAMMPSDumpWriter::Open(std::string file, bool bAppend) {
30 out_ = fopen(file.c_str(), bAppend ? "at" : "wt");
31}
32
33void LAMMPSDumpWriter::Close() { fclose(out_); }
34
36 Topology *top = conf;
37 Eigen::Matrix3d box = conf->getBox();
38 fprintf(out_, "ITEM: TIMESTEP\n%ld\n", top->getStep());
39 fprintf(out_, "ITEM: NUMBER OF ATOMS\n%li\n", (Index)top->Beads().size());
40 fprintf(out_, "ITEM: BOX BOUNDS pp pp pp\n");
41 fprintf(out_, "0 %f\n0 %f\n0 %f\n", box(0, 0) * conv::nm2ang,
42 box(1, 1) * conv::nm2ang, box(2, 2) * conv::nm2ang);
43
44 fprintf(out_, "ITEM: ATOMS id type x y z");
45 bool v = top->HasVel();
46 if (v) {
47 fprintf(out_, " vx vy vz");
48 }
49 bool f = top->HasForce();
50 if (f) {
51 fprintf(out_, " fx fy fz");
52 }
53 fprintf(out_, "\n");
54
55 for (const Bead &bead : conf->Beads()) {
56 Index type_id = conf->getBeadTypeId(bead.getType());
57
58 fprintf(out_, "%ld %li", bead.getId() + 1, type_id);
59 fprintf(out_, " %f %f %f", bead.getPos().x() * conv::nm2ang,
60 bead.getPos().y() * conv::nm2ang, bead.getPos().z() * conv::nm2ang);
61 if (v) {
62 fprintf(out_, " %f %f %f", bead.getVel().x() * conv::nm2ang,
63 bead.getVel().y() * conv::nm2ang,
64 bead.getVel().z() * conv::nm2ang);
65 }
66 if (f) {
67 fprintf(out_, " %f %f %f", bead.getF().x() * conv::kj2kcal / conv::nm2ang,
68 bead.getF().y() * conv::kj2kcal / conv::nm2ang,
69 bead.getF().z() * conv::kj2kcal / conv::nm2ang);
70 }
71 fprintf(out_, "\n");
72 }
73 fflush(out_);
74}
75
76} // namespace csg
77} // namespace votca
information about a bead
Definition bead.h:50
void Open(std::string file, bool bAppend=false) override
void Write(Topology *conf) override
topology of the whole system
Definition topology.h:81
Index getBeadTypeId(std::string type) const
Given a bead type this method returns the id associated with the type.
Definition topology.cc:133
BeadContainer & Beads()
Definition topology.h:169
const Eigen::Matrix3d & getBox() const
Definition topology.h:298
Index getStep() const
Definition topology.h:329
STL namespace.
const double kj2kcal
Definition constants.h:60
const double nm2ang
Definition constants.h:50
base class for all analysis tools
Definition basebead.h:33
Eigen::Index Index
Definition types.h:26