Skip to content
Snippets Groups Projects
Commit 05e3eea7 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

unique_ptr: some in mapping

parent 293d2d2a
No related branches found
No related tags found
No related merge requests found
......@@ -56,7 +56,7 @@ Mapping::Mapping(const ActionOptions&ao):
std::string mtype; parse("TYPE",mtype);
bool skipchecks; parseFlag("DISABLE_CHECKS",skipchecks);
// Setup the object that does the mapping
mymap = new PointWiseMapping( mtype, skipchecks );
mymap.reset( new PointWiseMapping( mtype, skipchecks ) );
// Read the properties we require
if( keywords.exists("PROPERTY") ) {
......@@ -124,10 +124,6 @@ void Mapping::turnOnDerivatives() {
needsDerivatives();
}
Mapping::~Mapping() {
delete mymap;
}
void Mapping::prepare() {
if( mymap->mappingNeedsSetup() ) {
// Get the arguments and atoms that are required
......
......@@ -28,6 +28,7 @@
#include "vesselbase/ActionWithVessel.h"
#include "reference/PointWiseMapping.h"
#include <vector>
#include <memory>
namespace PLMD {
......@@ -46,7 +47,7 @@ private:
// The derivative wrt to the distance from the frame
std::vector<double> dfframes;
/// This holds all the reference information
PointWiseMapping* mymap;
std::unique_ptr<PointWiseMapping> mymap;
/// The forces on each of the derivatives (used in apply)
std::vector<double> forcesToApply;
protected:
......@@ -69,7 +70,6 @@ protected:
public:
static void registerKeywords( Keywords& keys );
explicit Mapping(const ActionOptions&);
~Mapping();
/// Overload the virtual functions that appear in both ActionAtomistic and ActionWithArguments
void turnOnDerivatives();
void calculateNumericalDerivatives( ActionWithValue* a=NULL );
......
......@@ -176,7 +176,7 @@ private:
MultiValue myvals;
ReferenceValuePack mypack;
/// The position of the reference configuration (the one we align to)
ReferenceConfiguration* myref;
std::unique_ptr<ReferenceConfiguration> myref;
/// The eigenvectors we are interested in
std::vector<Direction> directions;
/// Stuff for applying forces
......@@ -184,7 +184,6 @@ private:
public:
static void registerKeywords( Keywords& keys );
explicit PCAVars(const ActionOptions&);
~PCAVars();
unsigned getNumberOfDerivatives();
void lockRequests();
void unlockRequests();
......@@ -239,8 +238,8 @@ PCAVars::PCAVars(const ActionOptions& ao):
expandArgKeywordInPDB( mypdb );
if(do_read) {
if( nfram==0 ) {
myref = metricRegister().create<ReferenceConfiguration>( mtype, mypdb );
Direction* tdir = dynamic_cast<Direction*>( myref );
myref.reset( metricRegister().create<ReferenceConfiguration>( mtype, mypdb ) );
Direction* tdir = dynamic_cast<Direction*>( myref.get() );
if( tdir ) error("first frame should be reference configuration - not direction of vector");
if( !myref->pcaIsEnabledForThisReference() ) error("can't do PCA with reference type " + mtype );
std::vector<std::string> remarks( mypdb.getRemark() ); std::string rtype;
......@@ -311,10 +310,6 @@ PCAVars::PCAVars(const ActionOptions& ao):
for(unsigned i=0; i<getNumberOfComponents(); ++i) getPntrToComponent(i)->resizeDerivatives(nder);
}
PCAVars::~PCAVars() {
delete myref;
}
unsigned PCAVars::getNumberOfDerivatives() {
if( getNumberOfAtoms()>0 ) {
return 3*getNumberOfAtoms() + 9 + getNumberOfArguments();
......
......@@ -207,14 +207,14 @@ int PathTools::main(FILE* in, FILE*out,Communicator& pc) {
std::string istart; parse("--start",istart); FILE* fp2=fopen(istart.c_str(),"r"); PDB mystartpdb;
if( istart.length()==0 ) error("input is missing use --istart + --iend or --path");
if( !mystartpdb.readFromFilepointer(fp2,false,0.1) ) error("could not read fila " + istart);
ReferenceConfiguration* sframe=metricRegister().create<ReferenceConfiguration>( mtype, mystartpdb );
std::unique_ptr<ReferenceConfiguration> sframe( metricRegister().create<ReferenceConfiguration>( mtype, mystartpdb ) );
fclose(fp2);
// Read final frame
std::string iend; parse("--end",iend); FILE* fp1=fopen(iend.c_str(),"r"); PDB myendpdb;
if( iend.length()==0 ) error("input is missing using --istart + --iend or --path");
if( !myendpdb.readFromFilepointer(fp1,false,0.1) ) error("could not read fila " + iend);
ReferenceConfiguration* eframe=metricRegister().create<ReferenceConfiguration>( mtype, myendpdb );
std::unique_ptr<ReferenceConfiguration> eframe( metricRegister().create<ReferenceConfiguration>( mtype, myendpdb ) );
fclose(fp1);
// Get atoms and arg requests
......@@ -286,7 +286,7 @@ int PathTools::main(FILE* in, FILE*out,Communicator& pc) {
for(unsigned i=0; i<final_path.size(); ++i) { final_path[i]->print( ofile, ofmt, 10. ); delete final_path[i]; }
// Delete the args as we don't need them anymore
for(unsigned i=0; i<args.size(); ++i) delete args[i];
ofile.close(); delete sframe; delete eframe; return 0;
ofile.close(); return 0;
}
} // End of namespace
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment