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 545 by tim, Fri May 27 21:11:24 2005 UTC vs.
Revision 1442 by gezelter, Mon May 10 17:28:26 2010 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, 24107 (2008).          
39 + * [4]  Vardeman & Gezelter, in progress (2009).                        
40   */
41  
42   #include <algorithm>
43 + #include <functional>
44   #include "applications/staticProps/DensityPlot.hpp"
45   #include "utils/simError.h"
46   #include "io/DumpReader.hpp"
47   #include "primitives/Molecule.hpp"
48   #include "utils/NumericConstant.hpp"
49 < namespace oopse {
49 > namespace OpenMD {
50  
51  
52 < DensityPlot::DensityPlot(SimInfo* info, const std::string& filename, const std::string& sele, double len, int nrbins)
52 > DensityPlot::DensityPlot(SimInfo* info, const std::string& filename, const std::string& sele, const std::string& cmSele, RealType len, int nrbins)
53    : StaticAnalyser(info, filename), selectionScript_(sele), evaluator_(info), seleMan_(info),
54 +    cmSelectionScript_(cmSele), cmEvaluator_(info), cmSeleMan_(info),    
55      len_(len), nRBins_(nrbins), halfLen_(len/2)     {
56  
57      setOutputName(getPrefix(filename) + ".density");
# Line 65 | Line 67 | DensityPlot::DensityPlot(SimInfo* info, const std::str
67      if (!evaluator_.isDynamic()) {
68        seleMan_.setSelectionSet(evaluator_.evaluate());
69      }
70 +
71 +    cmEvaluator_.loadScriptString(cmSele);
72 +    if (!cmEvaluator_.isDynamic()) {
73 +      cmSeleMan_.setSelectionSet(cmEvaluator_.evaluate());
74 +    }
75      
76 +    
77    }
78  
79   void DensityPlot::process() {
# Line 76 | Line 84 | void DensityPlot::process() {
84    
85    DumpReader reader(info_, dumpFilename_);    
86    int nFrames = reader.getNFrames();
79
87    for (int i = 0; i < nFrames; i += step_) {
88      reader.readFrame(i);
89      currentSnapshot_ = info_->getSnapshotManager()->getCurrentSnapshot();
# Line 89 | Line 96 | void DensityPlot::process() {
96          
97      }
98      
92    Vector3d cm = info_->getCom();
93
99      if (evaluator_.isDynamic()) {
100          seleMan_.setSelectionSet(evaluator_.evaluate());
101      }
102  
103 <    int i;        
104 <    for (StuntDouble* sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
105 <        Vector3d pos = sd->getPos() - cm;
101 <        currentSnapshot_->wrapVector(pos);
103 >    if (cmEvaluator_.isDynamic()) {
104 >        cmSeleMan_.setSelectionSet(cmEvaluator_.evaluate());
105 >    }
106  
107 <        int which = (pos.z() + halfLen_) / deltaR_;        
108 <        if (which < nRBins_ && which >=0 ) {
109 <          ++histogram_[which];
107 >    Vector3d origin = calcNewOrigin();
108 >
109 >    Mat3x3d hmat = currentSnapshot_->getHmat();
110 >    RealType slabVolume = deltaR_ * hmat(0, 0) * hmat(1, 1);
111 >    int k;
112 >    for (StuntDouble* sd = seleMan_.beginSelected(k); sd != NULL; sd = seleMan_.nextSelected(k)) {
113 >
114 >
115 >            if (!sd->isAtom()) {
116 >                sprintf( painCave.errMsg, "Can not calculate electron density if it is not atom\n");
117 >                painCave.severity = OPENMD_ERROR;
118 >                painCave.isFatal = 1;
119 >                simError();
120 >            }
121 >            
122 >            Atom* atom = static_cast<Atom*>(sd);
123 >            GenericData* data = atom->getAtomType()->getPropertyByName("nelectron");
124 >            if (data == NULL) {
125 >                sprintf( painCave.errMsg, "Can not find Parameters for nelectron\n");
126 >                painCave.severity = OPENMD_ERROR;
127 >                painCave.isFatal = 1;
128 >                simError();
129 >            }
130 >            
131 >            DoubleGenericData* doubleData = dynamic_cast<DoubleGenericData*>(data);
132 >            if (doubleData == NULL) {
133 >                sprintf( painCave.errMsg,
134 >                     "Can not cast GenericData to DoubleGenericData\n");
135 >                painCave.severity = OPENMD_ERROR;
136 >                painCave.isFatal = 1;
137 >                simError();  
138 >            }
139 >            
140 >            RealType nelectron = doubleData->getData();
141 >
142 >            data = atom->getAtomType()->getPropertyByName("LennardJones");
143 >            if (data == NULL) {
144 >                sprintf( painCave.errMsg, "Can not find Parameters for LennardJones\n");
145 >                painCave.severity = OPENMD_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 = OPENMD_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 >            }
180 >            
181 >            
182 >            
183          }        
184      }
108        
109  }
110  
111  //std::vector<int>::iterator it = std::max_element(histogram_.begin(), histogram_.end());
112  //int maxnum = *it;
185  
186 <  int nProcessed = nFrames / step_;
187 <  int ntot = info_->getNGlobalAtoms();
116 <  int maxnum = ntot * nProcessed;
117 <  std::transform(histogram_.begin(), histogram_.end(), density_.begin(), std::bind2nd(std::divides<double>(), maxnum));
186 >  int nProcessed = nFrames /step_;
187 >  std::transform(density_.begin(), density_.end(), density_.begin(), std::bind2nd(std::divides<RealType>(), nProcessed));  
188    writeDensity();
189 +        
190 +
191    
192   }
193  
194 + Vector3d DensityPlot::calcNewOrigin() {
195 +
196 +    int i;
197 +    Vector3d newOrigin(0.0);
198 +    RealType totalMass = 0.0;
199 +    for (StuntDouble* sd = seleMan_.beginSelected(i); sd != NULL; sd = seleMan_.nextSelected(i)) {
200 +        RealType mass = sd->getMass();
201 +        totalMass += mass;
202 +        newOrigin += sd->getPos() * mass;        
203 +    }
204 +    newOrigin /= totalMass;
205 +    return newOrigin;
206 + }
207 +
208   void DensityPlot::writeDensity() {
209      std::ofstream ofs(outputFilename_.c_str(), std::ios::binary);
210      if (ofs.is_open()) {
211        ofs << "#g(x, y, z)\n";
212 <      ofs << "#selection: (" << selectionScript_ << ")\t";
213 <      ofs << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "deltaR = " << deltaR_ <<"\n";
212 >      ofs << "#selection: (" << selectionScript_ << ")\n";
213 >      ofs << "#cmSelection:(" << cmSelectionScript_ << ")\n";
214 >      ofs << "#nRBins = " << nRBins_ << "\t maxLen = " << len_ << "\tdeltaR = " << deltaR_ <<"\n";
215        for (int i = 0; i < histogram_.size(); ++i) {
216            ofs << i*deltaR_ - halfLen_ <<"\t" << density_[i]<< std::endl;
217        }        

Comparing trunk/src/applications/staticProps/DensityPlot.cpp (property svn:keywords):
Revision 545 by tim, Fri May 27 21:11:24 2005 UTC vs.
Revision 1442 by gezelter, Mon May 10 17:28:26 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines