ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/OpenMD/trunk/src/applications/staticProps/DensityPlot.cpp
(Generate patch)

Comparing trunk/src/applications/staticProps/DensityPlot.cpp (file contents):
Revision 1078 by gezelter, Wed Oct 18 21:58:48 2006 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

# Line 6 | Line 6
6   * redistribute this software in source and binary code form, provided
7   * that the following conditions are met:
8   *
9 < * 1. Acknowledgement of the program authors must be made in any
10 < *    publication of scientific results based in part on use of the
11 < *    program.  An acceptable form of acknowledgement is citation of
12 < *    the article in which the program was described (Matthew
13 < *    A. Meineke, Charles F. Vardeman II, Teng Lin, Christopher
14 < *    J. Fennell and J. Daniel Gezelter, "OOPSE: An Object-Oriented
15 < *    Parallel Simulation Engine for Molecular Dynamics,"
16 < *    J. Comput. Chem. 26, pp. 252-271 (2005))
17 < *
18 < * 2. Redistributions of source code must retain the above copyright
9 > * 1. Redistributions of source code must retain the above copyright
10   *    notice, this list of conditions and the following disclaimer.
11   *
12 < * 3. Redistributions in binary form must reproduce the above copyright
12 > * 2. Redistributions in binary form must reproduce the above copyright
13   *    notice, this list of conditions and the following disclaimer in the
14   *    documentation and/or other materials provided with the
15   *    distribution.
# Line 37 | Line 28
28   * arising out of the use of or inability to use software, even if the
29   * University of Notre Dame has been advised of the possibility of
30   * such damages.
31 + *
32 + * SUPPORT OPEN SCIENCE!  If you use OpenMD or its source code in your
33 + * research, please cite the appropriate papers when you publish your
34 + * work.  Good starting points are:
35 + *                                                                      
36 + * [1]  Meineke, et al., J. Comp. Chem. 26, 252-271 (2005).            
37 + * [2]  Fennell & Gezelter, J. Chem. Phys. 124, 234104 (2006).          
38 + * [3]  Sun, Lin & Gezelter, J. Chem. Phys. 128, 234107 (2008).          
39 + * [4]  Kuang & Gezelter,  J. Chem. Phys. 133, 164101 (2010).
40 + * [5]  Vardeman, Stocker & Gezelter, J. Chem. Theory Comput. 7, 834 (2011).
41   */
42  
43   #include <algorithm>
# Line 46 | Line 47
47   #include "io/DumpReader.hpp"
48   #include "primitives/Molecule.hpp"
49   #include "utils/NumericConstant.hpp"
50 < namespace oopse {
50 > #include "types/LennardJonesAdapter.hpp"
51  
52 + namespace OpenMD {
53  
54 < DensityPlot::DensityPlot(SimInfo* info, const std::string& filename, const std::string& sele, const std::string& cmSele, RealType len, int nrbins)
55 <  : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info),
56 <    cmSelectionScript_(cmSele), cmEvaluator_(info), cmSeleMan_(info),    
57 <    len_(len), nRBins_(nrbins), halfLen_(len/2)     {
54 >  
55 >  DensityPlot::DensityPlot(SimInfo* info, const std::string& filename,
56 >                           const std::string& sele, const std::string& cmSele,
57 >                           RealType len, int nrbins)
58 >    : StaticAnalyser(info, filename),
59 >      len_(len), halfLen_(len/2), nRBins_(nrbins),
60 >      selectionScript_(sele), seleMan_(info), evaluator_(info),
61 >      cmSelectionScript_(cmSele), cmSeleMan_(info), cmEvaluator_(info) {
62  
63      setOutputName(getPrefix(filename) + ".density");
64 <
64 >    
65      deltaR_ = len_ /nRBins_;  
66      histogram_.resize(nRBins_);
67      density_.resize(nRBins_);
# Line 71 | Line 77 | DensityPlot::DensityPlot(SimInfo* info, const std::str
77      cmEvaluator_.loadScriptString(cmSele);
78      if (!cmEvaluator_.isDynamic()) {
79        cmSeleMan_.setSelectionSet(cmEvaluator_.evaluate());
80 <    }
75 <    
76 <    
80 >    }    
81    }
82  
83 < void DensityPlot::process() {
84 <  Molecule* mol;
85 <  RigidBody* rb;
86 <  SimInfo::MoleculeIterator mi;
87 <  Molecule::RigidBodyIterator rbIter;
84 <  
85 <  DumpReader reader(info_, dumpFilename_);    
86 <  int nFrames = reader.getNFrames();
87 <  for (int i = 0; i < nFrames; i += step_) {
88 <    reader.readFrame(i);
89 <    currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
83 >  void DensityPlot::process() {
84 >    Molecule* mol;
85 >    RigidBody* rb;
86 >    SimInfo::MoleculeIterator mi;
87 >    Molecule::RigidBodyIterator rbIter;
88  
89 <    for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) {
89 >    DumpReader reader(info_, dumpFilename_);    
90 >    int nFrames = reader.getNFrames();
91 >    for (int i = 0; i < nFrames; i += step_) {
92 >      reader.readFrame(i);
93 >      currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
94 >
95 >      for (mol = info_->beginMolecule(mi); mol != NULL;
96 >           mol = info_->nextMolecule(mi)) {
97          //change the positions of atoms which belong to the rigidbodies
98 <        for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) {
99 <            rb->updateAtoms();
98 >        for (rb = mol->beginRigidBody(rbIter); rb != NULL;
99 >             rb = mol->nextRigidBody(rbIter)) {
100 >          rb->updateAtoms();
101          }
102          
103 <    }
103 >      }
104      
105 <    if (evaluator_.isDynamic()) {
105 >      if (evaluator_.isDynamic()) {
106          seleMan_.setSelectionSet(evaluator_.evaluate());
107 <    }
107 >      }
108  
109 <    if (cmEvaluator_.isDynamic()) {
109 >      if (cmEvaluator_.isDynamic()) {
110          cmSeleMan_.setSelectionSet(cmEvaluator_.evaluate());
111 <    }
111 >      }
112  
113 <    Vector3d origin = calcNewOrigin();
113 >      Vector3d origin = calcNewOrigin();
114  
115 <    Mat3x3d hmat = currentSnapshot_->getHmat();
116 <    RealType slabVolume = deltaR_ * hmat(0, 0) * hmat(1, 1);
117 <    int k;
118 <    for (StuntDouble* sd = seleMan_.beginSelected(k); sd != NULL; sd = seleMan_.nextSelected(k)) {
115 >      Mat3x3d hmat = currentSnapshot_->getHmat();
116 >      RealType slabVolume = deltaR_ * hmat(0, 0) * hmat(1, 1);
117 >      int k;
118 >      for (StuntDouble* sd = seleMan_.beginSelected(k); sd != NULL;
119 >           sd = seleMan_.nextSelected(k)) {
120  
121  
122 <            if (!sd->isAtom()) {
123 <                sprintf( painCave.errMsg, "Can not calculate electron density if it is not atom\n");
124 <                painCave.severity = OOPSE_ERROR;
125 <                painCave.isFatal = 1;
126 <                simError();
127 <            }
122 >        if (!sd->isAtom()) {
123 >          sprintf( painCave.errMsg,
124 >                   "Can not calculate electron density if it is not atom\n");
125 >          painCave.severity = OPENMD_ERROR;
126 >          painCave.isFatal = 1;
127 >          simError();
128 >        }
129              
130 <            Atom* atom = static_cast<Atom*>(sd);
131 <            GenericData* data = atom->getAtomType()->getPropertyByName("nelectron");
132 <            if (data == NULL) {
133 <                sprintf( painCave.errMsg, "Can not find Parameters for nelectron\n");
134 <                painCave.severity = OOPSE_ERROR;
135 <                painCave.isFatal = 1;
136 <                simError();
137 <            }
130 >        Atom* atom = static_cast<Atom*>(sd);
131 >        GenericData* data = atom->getAtomType()->getPropertyByName("nelectron");
132 >        if (data == NULL) {
133 >          sprintf( painCave.errMsg, "Can not find Parameters for nelectron\n");
134 >          painCave.severity = OPENMD_ERROR;
135 >          painCave.isFatal = 1;
136 >          simError();
137 >        }
138              
139 <            DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
140 <            if (doubleData == NULL) {
141 <                sprintf( painCave.errMsg,
142 <                     "Can not cast GenericData to DoubleGenericData\n");
143 <                painCave.severity = OOPSE_ERROR;
144 <                painCave.isFatal = 1;
145 <                simError();  
146 <            }
139 >        DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
140 >        if (doubleData == NULL) {
141 >          sprintf( painCave.errMsg,
142 >                   "Can not cast GenericData to DoubleGenericData\n");
143 >          painCave.severity = OPENMD_ERROR;
144 >          painCave.isFatal = 1;
145 >          simError();  
146 >        }
147              
148 <            RealType nelectron = doubleData->getData();
149 <
150 <            data = atom->getAtomType()->getPropertyByName("LennardJones");
151 <            if (data == NULL) {
144 <                sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n");
145 <                painCave.severity = OOPSE_ERROR;
146 <                painCave.isFatal = 1;
147 <                simError();
148 <            }
149 <
150 <            LJParamGenericData* ljData = dynamic_cast<LJParamGenericData*>(data);
151 <            if (ljData == NULL) {
152 <                sprintf( painCave.errMsg,
153 <                     "Can not cast GenericData to LJParam\n");
154 <                painCave.severity = OOPSE_ERROR;
155 <                painCave.isFatal = 1;
156 <                simError();          
157 <            }
158 <
159 <            LJParam ljParam = ljData->getData();
160 <            RealType sigma = ljParam.sigma * 0.5;
161 <            RealType sigma2 = sigma * sigma;
162 <
163 <            Vector3d pos = sd->getPos() - origin;
164 <            for (int j =0; j < nRBins_; ++j) {
165 <                Vector3d tmp(pos);
166 <                RealType zdist =j * deltaR_ - halfLen_;
167 <                tmp[2] += zdist;
168 <                if (usePeriodicBoundaryConditions_)
169 <                  currentSnapshot_->wrapVector(tmp);
170 <
171 <                RealType wrappedZdist = tmp.z() + halfLen_;
172 <                if (wrappedZdist < 0.0 || wrappedZdist > len_) {
173 <                    continue;
174 <                }
175 <                
176 <                int which =wrappedZdist / deltaR_;        
177 <                density_[which] += nelectron * exp(-zdist*zdist/(sigma2*2.0)) /(slabVolume* sqrt(2*NumericConstant::PI*sigma*sigma));
178 <                    
179 <            }
148 >        RealType nelectron = doubleData->getData();
149 >        LennardJonesAdapter lja = LennardJonesAdapter(atom->getAtomType());
150 >        RealType sigma = lja.getSigma() * 0.5;
151 >        RealType sigma2 = sigma * sigma;
152              
153 <            
154 <            
155 <        }        
153 >        Vector3d pos = sd->getPos() - origin;
154 >        for (int j =0; j < nRBins_; ++j) {
155 >          Vector3d tmp(pos);
156 >          RealType zdist =j * deltaR_ - halfLen_;
157 >          tmp[2] += zdist;
158 >          if (usePeriodicBoundaryConditions_)
159 >            currentSnapshot_->wrapVector(tmp);
160 >              
161 >          RealType wrappedZdist = tmp.z() + halfLen_;
162 >          if (wrappedZdist < 0.0 || wrappedZdist > len_) {
163 >            continue;
164 >          }
165 >              
166 >          int which = int(wrappedZdist / deltaR_);
167 >          density_[which] += nelectron * exp(-zdist*zdist/(sigma2*2.0)) /(slabVolume* sqrt(2*NumericConstant::PI*sigma*sigma));
168 >              
169 >        }            
170 >      }        
171      }
172 <
173 <  int nProcessed = nFrames /step_;
174 <  std::transform(density_.begin(), density_.end(), density_.begin(), std::bind2nd(std::divides<RealType>(), nProcessed));  
175 <  writeDensity();
172 >  
173 >    int nProcessed = nFrames /step_;
174 >    std::transform(density_.begin(), density_.end(), density_.begin(),
175 >                   std::bind2nd(std::divides<RealType>(), nProcessed));  
176 >    writeDensity();
177          
178  
179    
180 < }
180 >  }
181  
182 < Vector3d DensityPlot::calcNewOrigin() {
182 >  Vector3d DensityPlot::calcNewOrigin() {
183  
184      int i;
185      Vector3d newOrigin(0.0);
186      RealType totalMass = 0.0;
187 <    for (StuntDouble* sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
188 <        RealType mass = sd->getMass();
189 <        totalMass += mass;
190 <        newOrigin += sd->getPos() * mass;        
187 >    for (StuntDouble* sd = seleMan_.beginSelected(i); sd != NULL;
188 >         sd = seleMan_.nextSelected(i)) {
189 >      RealType mass = sd->getMass();
190 >      totalMass += mass;
191 >      newOrigin += sd->getPos() * mass;        
192      }
193      newOrigin /= totalMass;
194      return newOrigin;
195 < }
195 >  }
196  
197 < void DensityPlot::writeDensity() {
197 >  void DensityPlot::writeDensity() {
198      std::ofstream ofs(outputFilename_.c_str(), std::ios::binary);
199      if (ofs.is_open()) {
200        ofs << "#g(x, y, z)\n";
201        ofs << "#selection: (" << selectionScript_ << ")\n";
202        ofs << "#cmSelection:(" << cmSelectionScript_ << ")\n";
203 <      ofs << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "\tdeltaR = " << deltaR_ <<"\n";
204 <      for (int i = 0; i < histogram_.size(); ++i) {
205 <          ofs << i*deltaR_ - halfLen_ <<"\t" << density_[i]<< std::endl;
203 >      ofs << "#nRBins = " << nRBins_ << "\t maxLen = "
204 >          << len_ << "\tdeltaR = " << deltaR_ <<"\n";
205 >      for (unsigned int i = 0; i < histogram_.size(); ++i) {
206 >        ofs << i*deltaR_ - halfLen_ <<"\t" << density_[i]<< std::endl;
207        }        
208      } else {
209  
210 <      sprintf(painCave.errMsg, "DensityPlot: unable to open %s\n", outputFilename_.c_str());
210 >      sprintf(painCave.errMsg, "DensityPlot: unable to open %s\n",
211 >              outputFilename_.c_str());
212        painCave.isFatal = 1;
213        simError();  
214      }
# Line 225 | Line 216 | void DensityPlot::writeDensity() {
216      ofs.close();
217  
218  
219 < }
219 >  }
220  
221   }
222  

Comparing trunk/src/applications/staticProps/DensityPlot.cpp (property svn:keywords):
Revision 1078 by gezelter, Wed Oct 18 21:58:48 2006 UTC vs.
Revision 2071 by gezelter, Sat Mar 7 21:41:51 2015 UTC

# Line 0 | Line 1
1 + Author Id Revision Date

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines