Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 : Copyright (c) 2016-2018 The plumed team
3 : (see the PEOPLE file at the root of the distribution for a list of names)
4 :
5 : See http://www.plumed.org for more information.
6 :
7 : This file is part of plumed, version 2.
8 :
9 : plumed is free software: you can redistribute it and/or modify
10 : it under the terms of the GNU Lesser General Public License as published by
11 : the Free Software Foundation, either version 3 of the License, or
12 : (at your option) any later version.
13 :
14 : plumed is distributed in the hope that it will be useful,
15 : but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : GNU Lesser General Public License for more details.
18 :
19 : You should have received a copy of the GNU Lesser General Public License
20 : along with plumed. If not, see <http://www.gnu.org/licenses/>.
21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
22 : #include "ContourFindingBase.h"
23 : #include "vesselbase/StoreDataVessel.h"
24 : #include "core/PlumedMain.h"
25 : #include "core/Atoms.h"
26 :
27 : namespace PLMD {
28 : namespace gridtools {
29 :
30 6 : void ContourFindingBase::registerKeywords( Keywords& keys ) {
31 6 : ActionWithInputGrid::registerKeywords( keys );
32 6 : keys.add("compulsory","CONTOUR","the value we would like to draw the contour at in the space");
33 6 : keys.add("compulsory","FILE","file on which to output coordinates");
34 6 : keys.add("compulsory","UNITS","PLUMED","the units in which to print out the coordinates. PLUMED means internal PLUMED units");
35 6 : keys.add("optional", "PRECISION","The number of digits in trajectory file");
36 6 : keys.remove("KERNEL"); keys.remove("BANDWIDTH");
37 6 : }
38 :
39 3 : ContourFindingBase::ContourFindingBase(const ActionOptions&ao):
40 : Action(ao),
41 : ActionWithInputGrid(ao),
42 : mymin(this),
43 3 : mydata(NULL)
44 : {
45 3 : if( ingrid->noDerivatives() ) error("cannot find contours if input grid has no derivatives");
46 3 : parse("CONTOUR",contour);
47 3 : log.printf(" calculating dividing surface along which function equals %f \n", contour);
48 :
49 3 : if( keywords.exists("FILE") ) {
50 2 : std::string file; parse("FILE",file);
51 2 : if(file.length()==0 && keywords.style("FILE","compulsory") ) error("name out output file was not specified");
52 2 : else if( file.length()>0 ) {
53 2 : std::string type=Tools::extension(file);
54 2 : log<<" file name "<<file<<"\n";
55 2 : if(type!="xyz") error("can only print xyz file type with contour finding");
56 :
57 2 : fmt_xyz="%f";
58 4 : std::string precision; parse("PRECISION",precision);
59 2 : if(precision.length()>0) {
60 2 : int p; Tools::convert(precision,p);
61 2 : log<<" with precision "<<p<<"\n";
62 4 : std::string a,b;
63 2 : Tools::convert(p+5,a);
64 2 : Tools::convert(p,b);
65 4 : fmt_xyz="%"+a+"."+b+"f";
66 : }
67 :
68 4 : std::string unitname; parse("UNITS",unitname);
69 2 : if(unitname!="PLUMED") {
70 1 : Units myunit; myunit.setLength(unitname);
71 1 : lenunit=plumed.getAtoms().getUnits().getLength()/myunit.getLength();
72 : }
73 1 : else lenunit=1.0;
74 :
75 2 : of.link(*this); of.open(file);
76 :
77 : // Now create a store data vessel to hold the points
78 4 : mydata=buildDataStashes( NULL );
79 2 : }
80 : }
81 3 : }
82 :
83 4 : void ContourFindingBase::finishAveraging() {
84 : // And this looks after the output
85 4 : if( mydata ) {
86 2 : std::vector<double> point( 1 + ingrid->getDimension() );
87 2 : of.printf("%u\n",mydata->getNumberOfStoredValues());
88 2 : of.printf("Points found on isocontour\n");
89 656 : for(unsigned i=0; i<mydata->getNumberOfStoredValues(); ++i) {
90 654 : mydata->retrieveSequentialValue( i, false, point ); of.printf("X");
91 654 : for(unsigned j=0; j<ingrid->getDimension(); ++j) of.printf( (" " + fmt_xyz).c_str(), lenunit*point[1+j] );
92 654 : of.printf("\n");
93 2 : }
94 : }
95 4 : }
96 :
97 : }
98 2523 : }
|