diff --git a/CHANGELOG.md b/CHANGELOG.md index 547f6e9..ee3fa60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ * only documentation of principal version changes in CHANGELOG LeMonADE 1.0 -* bare copy of LeMonADE library from ITP (Leibniz-Institute for Polymer Research IPF) with basic functinonalities +* bare copy of LeMonADE library from ITP (Leibniz-Institute of Polymer Research Dresden IPF) with basic functionalities LeMonADE 2.0 * adding abstract system setup Updater: UpdaterAbstractCreate @@ -25,3 +25,7 @@ LeMonADE 2.2 * add analyzers for the calculation of the mean-square displacement * add various features and moves to enable reactive and reversible bonds +LeMonADE 2.2.2 +* HotFix for default R250 values +* ColdFix for implementation of RNG Mersenne Twister +* ColdFix for ResultFormattingTools diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ee0fe0..24abd6b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,10 +31,10 @@ CMAKE_MINIMUM_REQUIRED (VERSION 2.6.2) PROJECT (LeMonADE) SET (APPLICATION_NAME "LeMonADE") SET (APPLICATION_CODENAME "${PROJECT_NAME}") -SET (APPLICATION_COPYRIGHT_YEARS "2013-2020") +SET (APPLICATION_COPYRIGHT_YEARS "2013-2021") SET (APPLICATION_VERSION_MAJOR "2") SET (APPLICATION_VERSION_MINOR "2") -SET (APPLICATION_VERSION_PATCH "1") +SET (APPLICATION_VERSION_PATCH "2") # diff --git a/README.md b/README.md index 0fd4126..7e7daad 100644 --- a/README.md +++ b/README.md @@ -103,6 +103,8 @@ Find the information about active developers, former contributors, and people wh ## References This library has been used in the following publications (without guarantee for completeness) +* *"Multimolecular Structure Formation with Linear Dendritic Copolymers"*; M. Wengenmayr, R. Dockhorn, J.-U. Sommer; [Macromolecules XX, XXXX-XXXX (2021)](https://doi.org/10.1021/acs.macromol.1c00226) +* *"Analysis of the Gel Point of Polymer Model Networks by Computer Simulations"*; M. Lang, T. Müller; [Macromolecules 53, 498-512 (2020)](https://doi.org/10.1021/acs.macromol.9b02217) * *"Polyolefins Formed by Chain Walking Catalysis—A Matter of Branching Density Only?"*; R. Dockhorn, L. Plüschke, M. Geisler, J. Zessin, P. Lindner, R. Mundil, J. Merna, J.-U. Sommer, A. Lederer; [J. Am. Chem. Soc. 141, 15586–15596 (2019)](https://pubs.acs.org/doi/10.1021/jacs.9b06785) * *"Tendomers – force sensitive bis-rotaxanes with jump-like deformation behavior"*; T. Müller, J.-U. Sommer, M. Lang; [Soft Matter, 15, 3671-3679 (2019)](https://doi.org/10.1039/C9SM00292H) * *"Dendrimers in Solution of Linear Polymers: Crowding Effects"*; M. Wengenmayr, R. Dockhorn, J.-U. Sommer; [Macromolecules 52, 2616–2626 (2019)](https://doi.org/10.1021/acs.macromol.9b00010) diff --git a/include/LeMonADE/Version.h b/include/LeMonADE/Version.h index 3723ddd..48683c8 100644 --- a/include/LeMonADE/Version.h +++ b/include/LeMonADE/Version.h @@ -37,12 +37,12 @@ along with LeMonADE. If not, see . #define APPLICATION_NAME "LeMonADE" #define APPLICATION_CODENAME "LeMonADE" -#define APPLICATION_COPYRIGHT_YEARS "2013-2020" +#define APPLICATION_COPYRIGHT_YEARS "2013-2021" #define APPLICATION_VERSION_MAJOR 2 #define APPLICATION_VERSION_MINOR 2 -#define APPLICATION_VERSION_PATCH 1 +#define APPLICATION_VERSION_PATCH 2 #define APPLICATION_VERSION_TYPE "Release" -#define APPLICATION_VERSION_STRING "2.2.1-(C)2013-2020-Release" +#define APPLICATION_VERSION_STRING "2.2.2-(C)2013-2021-Release" #define APPLICATION_ID "LeMonADE.LeMonADE" #ifndef APPLICATION_VERSION_MAJOR diff --git a/include/LeMonADE/analyzer/AnalyzerAbstractDump.h b/include/LeMonADE/analyzer/AnalyzerAbstractDump.h index 8979a1e..5c56d36 100644 --- a/include/LeMonADE/analyzer/AnalyzerAbstractDump.h +++ b/include/LeMonADE/analyzer/AnalyzerAbstractDump.h @@ -15,8 +15,6 @@ #include #include #include -#include -#include /************************************************************************* * definition of AnalyzerAbstractDump class @@ -98,8 +96,12 @@ template < class IngredientsType , class T > class AnalyzerAbstractDump : public uint32_t getNumberOfColumns(){ return NColumns; } //! set the buffer size for dumping data void setBufferSize(uint32_t bufferSize_){ bufferSize=bufferSize_;} - //! get the buffer size - uint32_t getBufferSize(){return bufferSize;} + //! get the buffer size + uint32_t getBufferSize(){return bufferSize;} + //! get the variable isFirstFileDump + bool getIsFirstFileDump() const { return isFirstFileDump; } + //! reset the variable isFirstFileDump to false (could be used if the filename changes in between data dumpings) + void resetIsFirstFileDump() {isFirstFileDump=true;} }; /************************************************************************* diff --git a/include/LeMonADE/analyzer/AnalyzerWriteBfmFile.h b/include/LeMonADE/analyzer/AnalyzerWriteBfmFile.h index 06d6d7f..4529359 100644 --- a/include/LeMonADE/analyzer/AnalyzerWriteBfmFile.h +++ b/include/LeMonADE/analyzer/AnalyzerWriteBfmFile.h @@ -134,6 +134,11 @@ class AnalyzerWriteBfmFile: public AbstractAnalyzer * **/ virtual void cleanup(){}; +protected: + + //! set the name of the file for output which only works for the overwrite case + void setFilename(std::string filename){_filename=filename;} + private: //! Write Writes that only need to be in the header void writeHeader(); diff --git a/include/LeMonADE/core/Molecules.h b/include/LeMonADE/core/Molecules.h index d3de749..4967c48 100644 --- a/include/LeMonADE/core/Molecules.h +++ b/include/LeMonADE/core/Molecules.h @@ -133,7 +133,7 @@ template < class Vertex, uint max_connectivity = 7, class Edge = int > class Mol * * @return The actual time in the graph. */ - const uint64_t getAge() const {return myAge;} + uint64_t getAge() const {return myAge;} /** diff --git a/include/LeMonADE/feature/FeatureBondset.h b/include/LeMonADE/feature/FeatureBondset.h index 3ae213e..0bc8e64 100644 --- a/include/LeMonADE/feature/FeatureBondset.h +++ b/include/LeMonADE/feature/FeatureBondset.h @@ -223,17 +223,15 @@ class FeatureBondset : public Feature template bool checkMove(const IngredientsType& ingredients, const MoveLabelBase& move) const { - - //get the number of bond partners of the particle to be moved - int32_t MonID=move.getIndex()+move.getDir(); - if ( MonID == -1 ) return false; - uint32_t ID=move.getConnectedLabel(); - const typename IngredientsType::molecules_type& molecules=ingredients.getMolecules(); - if (ID == 0 ) return true; - ID--; - auto bond(molecules[MonID].getVector3D()-molecules[ID].getVector3D()); - if (!bondset.isValidStrongCheck( bond ) ) return false; - if ( bond.getLength()>3.) return false; // otherwise I could get xtraps + //get the number of bond partners of the particle to be moved + int32_t MonID=move.getIndex()+move.getDir(); + if ( MonID == -1 ) return false; + uint32_t ID=move.getConnectedLabel(); + const typename IngredientsType::molecules_type& molecules=ingredients.getMolecules(); + if (ID == 0 ) return true; + ID--; + auto bond(molecules[MonID].getVector3D()-molecules[ID].getVector3D()); + if (!bondset.isValidStrongCheck( bond ) ) return false; return true; } diff --git a/include/LeMonADE/feature/FeatureLabel.h b/include/LeMonADE/feature/FeatureLabel.h index 7eece62..976ec6f 100644 --- a/include/LeMonADE/feature/FeatureLabel.h +++ b/include/LeMonADE/feature/FeatureLabel.h @@ -55,7 +55,7 @@ class MonomerLabel MonomerLabel():label(0){} //! is labeled - const uint32_t getLabel() const {return label;} + uint32_t getLabel() const {return label;} //! set label on/off void setLabel(uint32_t label_){ label=label_;} diff --git a/include/LeMonADE/feature/FeatureLinearForce.h b/include/LeMonADE/feature/FeatureLinearForce.h new file mode 100644 index 0000000..4b8e8a6 --- /dev/null +++ b/include/LeMonADE/feature/FeatureLinearForce.h @@ -0,0 +1,317 @@ +/*-------------------------------------------------------------------------------- + ooo L attice-based | + o\.|./o e xtensible | LeMonADE: An Open Source Implementation of the + o\.\|/./o Mon te-Carlo | Bond-Fluctuation-Model for Polymers +oo---0---oo A lgorithm and | + o/./|\.\o D evelopment | Copyright (C) 2013-2015 by + o/.|.\o E nvironment | LeMonADE Principal Developers (see AUTHORS) + ooo | +---------------------------------------------------------------------------------- + +This file is part of LeMonADE. + +LeMonADE is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +LeMonADE is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with LeMonADE. If not, see . + +--------------------------------------------------------------------------------*/ + +#ifndef LEMONADE_LINEARFORCE_H +#define LEMONADE_LINEARFORCE_H + +#include +#include +#include +#include +#include +#include +#include + +/*****************************************************************************/ +/** + * @file + * @date 2021/03/18 + * @author Toni & Bodonki + * + * @class FeatureLinearForce + * @brief This Feature applies a force on certain monomers. + * @todo Substitute the FeatureAttributes<> by appropriate monomer extension + * */ +/*****************************************************************************/ + + + + +class FeatureLinearForce:public Feature +{ +public: + + FeatureLinearForce(): ForceOn(false){}; + virtual ~FeatureLinearForce(){}; + + //the FeatureBoltzmann: adds a probability for the move + //the FeatureAttributes<>: labels the monomers for beeing force sensitive + typedef LOKI_TYPELIST_2(FeatureBoltzmann,FeatureAttributes<>) required_features_back; + + //! For all unknown moves: this does nothing + template + bool checkMove(const IngredientsType& ingredients,const MoveBase& move) const{return true;}; + + //! check for a MoveLocalSc + template + bool checkMove(const IngredientsType& ingredients,MoveLocalSc& move) const; + + //! check for a MoveLocalScDiag + template + bool checkMove(const IngredientsType& ingredients,MoveLocalScDiag& move) const; + + //! set the strength of the force + void setAmplitudeForce(double amplitudeForce){ + Amplitude_Force = amplitudeForce; + prob=exp(-Amplitude_Force); + } + + //! set force on or off + void setForceOn(bool forceOn){ForceOn = forceOn;} + + //! get strength of the force + double getAmplitudeForce() const {return Amplitude_Force;} + + //! applies a force on the monomers or not + bool isForceOn() const {return ForceOn;} + + //! Export the relevant functionality for reading bfm-files to the responsible reader object + template + void exportRead(FileImport & fileReader); + + //! Export the relevant functionality for writing bfm-files to the responsible writer object + template + void exportWrite(AnalyzerWriteBfmFile & fileWriter) const; +private: + + //! Force is On (True) or Off (False) + bool ForceOn; + //! force in x direction + double Amplitude_Force; + //!probability + double prob; + +}; +//////////////////////////////////////////////////////////////////////////////// +//////////define member functions ////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +template +bool FeatureLinearForce::checkMove(const IngredientsType& ingredients, MoveLocalSc& move) const +{ + if(ForceOn){ + + const uint32_t monoIndex(move.getIndex()); + const int32_t tag(ingredients.getMolecules()[monoIndex].getAttributeTag()); + const int32_t dx(move.getDir().getX()); + //Metropolis: zeta = exp (-dV) + //dV=f*dr + // positive force applied on attribute 4 and negative force on attribute 5 + if( ( tag == 4 ) && ( dx == 1 ) ){ + move.multiplyProbability(prob); + return true; + } + if( ( tag == 5 ) && ( dx == -1 ) ){ + move.multiplyProbability(prob); + return true; + } + } + return true; +} +template +bool FeatureLinearForce::checkMove(const IngredientsType& ingredients, MoveLocalScDiag& move) const +{ + if(ForceOn){ + const uint32_t monoIndex(move.getIndex()); + const int32_t tag(ingredients.getMolecules()[monoIndex].getAttributeTag()); + const int32_t dx(move.getDir().getX()); + //Metropolis: zeta = exp (-dV) + //dV=f*dr + // positive force applied on attribute 4 and negative force on attribute 5 + if( ( tag == 4 ) && ( dx == 1 ) ){ + move.multiplyProbability(prob); + return true; + } + if( ( tag == 5 ) && ( dx == -1 ) ){ + move.multiplyProbability(prob); + return true; + } + } + return true; +} + +/*****************************************************************/ +/** + * @class ReadForceFieldOn + * + * @brief Handles BFM-File-Reads \b #!force_field_on + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template < class IngredientsType> +class ReadForceFieldOn: public ReadToDestination +{ +public: + ReadForceFieldOn(IngredientsType& i):ReadToDestination(i){} + virtual ~ReadForceFieldOn(){} + virtual void execute(); +}; + +template +void ReadForceFieldOn::execute() +{ + std::cout<<"reading FieldIsOn..."; + + bool fieldIsOn = false; + IngredientsType& ingredients=this->getDestination(); + std::istream& source=this->getInputStream(); + + std::string line; + getline(source,line); + fieldIsOn = atoi(line.c_str()); + std::cout << "#!force_field_on=" << (fieldIsOn? "True" : " False" ) << std::endl; + + ingredients.setForceOn(fieldIsOn); +} + +/*****************************************************************/ +/** + * @class WriteForceFieldOn + * + * @brief Handles BFM-File-Write \b #!force_field_on + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +class WriteForceFieldOn:public AbstractWrite +{ +public: + WriteForceFieldOn(const IngredientsType& i) + :AbstractWrite(i){this->setHeaderOnly(false);} + + virtual ~WriteForceFieldOn(){} + + virtual void writeStream(std::ostream& strm); +}; + +template +void WriteForceFieldOn::writeStream(std::ostream& stream) +{ + stream<<"#!force_field_on=" << (this->getSource().isForceOn() ? "1" : "0") << std::endl<< std::endl; +} + + +/*****************************************************************/ +/** + * @class ReadAmplitudeForce + * + * @brief Handles BFM-File-Reads \b #!force_amplitude + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template < class IngredientsType> +class ReadAmplitudeForce: public ReadToDestination +{ +public: + ReadAmplitudeForce(IngredientsType& i):ReadToDestination(i){} + virtual ~ReadAmplitudeForce(){} + virtual void execute(); +}; + +template +void ReadAmplitudeForce::execute() +{ + std::cout<<"reading AmplitudeForce..."; + + double amplitudeForce = 0.0; + IngredientsType& ingredients=this->getDestination(); + std::istream& source=this->getInputStream(); + + std::string line; + getline(source,line); + amplitudeForce = atof(line.c_str()); + std::cout << "#!force_amplitude=" << (amplitudeForce) << std::endl; + + ingredients.setAmplitudeForce(amplitudeForce); +} + + +/*****************************************************************/ +/** + * @class WriteAmplitudeForce + * + * @brief Handles BFM-File-Write \b #!force_amplitude + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +class WriteAmplitudeForce:public AbstractWrite +{ +public: + WriteAmplitudeForce(const IngredientsType& i) + :AbstractWrite(i){this->setHeaderOnly(false);} + + virtual ~WriteAmplitudeForce(){} + + virtual void writeStream(std::ostream& strm); +}; + +template +void WriteAmplitudeForce::writeStream(std::ostream& stream) +{ + stream<<"#!force_amplitude=" << (this->getSource().getAmplitudeForce()) << std::endl<< std::endl; +} + + + +/** + * @details The function is called by the Ingredients class when an object of type Ingredients + * is associated with an object of type FileImport. The export of the Reads is thus + * taken care automatically when it becomes necessary.\n + * Registered Read-In Commands: + * * #!shear_field_on + * * #!force_amplitude + * + * @param fileReader File importer for the bfm-file + * @param destination List of Feature to write-in from the read values. + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +void FeatureLinearForce::exportRead(FileImport< IngredientsType >& fileReader) +{ + fileReader.registerRead("#!force_field_on", new ReadForceFieldOn(*this)); + fileReader.registerRead("#!force_amplitude", new ReadAmplitudeForce(*this)); + +} + +/** + * The function is called by the Ingredients class when an object of type Ingredients + * is associated with an object of type AnalyzerWriteBfmFile. The export of the Writes is thus + * taken care automatically when it becomes necessary.\n + * Registered Write-Out Commands: + * * #!shear_field_on + * * #!force_amplitude + * + * @param fileWriter File writer for the bfm-file. + */ +template +void FeatureLinearForce::exportWrite(AnalyzerWriteBfmFile< IngredientsType >& fileWriter) const +{ + fileWriter.registerWrite("#!force_field_on",new WriteForceFieldOn(*this)); + fileWriter.registerWrite("#!force_amplitude", new WriteAmplitudeForce(*this)); + +} + + + + +#endif /*FEATURE_LINEARFORCE_H*/ diff --git a/include/LeMonADE/feature/FeatureReactiveBonds.h b/include/LeMonADE/feature/FeatureReactiveBonds.h index d501a2a..80570e5 100644 --- a/include/LeMonADE/feature/FeatureReactiveBonds.h +++ b/include/LeMonADE/feature/FeatureReactiveBonds.h @@ -60,10 +60,10 @@ class MonomerReactivity MonomerReactivity():reactivity(false),numMaxLinks(0){} //! Getting the reactivity of the monomer. - const bool isReactive() const {return reactivity;} + bool isReactive() const {return reactivity;} //! Getting the number of maximum possible bonds for the monomer. - const uint32_t getNumMaxLinks() const {return numMaxLinks;}; + uint32_t getNumMaxLinks() const {return numMaxLinks;}; MonomerReactivity& operator= (const MonomerReactivity source) { @@ -79,13 +79,13 @@ class MonomerReactivity numMaxLinks = react.getNumMaxLinks(); /// \todo There should be a check in the function to test against the "default" maximum connectivity for consistency reason. } - const bool operator == (const MonomerReactivity &react) const + bool operator == (const MonomerReactivity &react) const { if ( react.getNumMaxLinks() != numMaxLinks ) return false; if ( react.isReactive() != reactivity ) return false; return true; } - const bool operator!= (const MonomerReactivity &react) const + bool operator!= (const MonomerReactivity &react) const { return !(*this == react); } @@ -205,103 +205,113 @@ class WriteReactivity:public AbstractWrite /////////////////////////////////////////////////////////////////////////////// class FeatureReactiveBonds : public Feature { - typedef std::pair < uint32_t, uint32_t > BondPair; - typedef uint32_t edge_type; + typedef std::pair < uint32_t, uint32_t > BondPair; + typedef uint32_t edge_type; public: - //! This Feature requires a monomer_extensions. - typedef LOKI_TYPELIST_1(MonomerReactivity) monomer_extensions; - typedef LOKI_TYPELIST_2(FeatureBreak, FeatureConnectionSc) required_features_back; + //! This Feature requires a monomer_extensions. + typedef LOKI_TYPELIST_1(MonomerReactivity) monomer_extensions; + typedef LOKI_TYPELIST_2(FeatureBreak, FeatureConnectionSc) required_features_back; + + FeatureReactiveBonds():nReactedBonds(0),nReactiveSites(0){}; + + //! Export the relevant functionality for reading bfm-files to the responsible reader object + template + void exportRead(FileImport& fileReader); + + //! Export the relevant functionality for writing bfm-files to the responsible writer object + template + void exportWrite(AnalyzerWriteBfmFile& fileWriter) const; - FeatureReactiveBonds():nReactedBonds(0),nReactiveSites(0){}; + //! check base move - always true + template + bool checkMove(const IngredientsType& ingredients, const MoveBase& move) const{return true;}; + + //! check base connection move + template + bool checkMove(const IngredientsType& ingredients, const MoveConnectBase& move) const; + + //! check base break move + template + bool checkMove(const IngredientsType& ingredients, const MoveBreakBase& move) const ; + + //! check movebreakreactive + template + bool checkMove(const IngredientsType& ingredients, const MoveBreakReactive& move) const {return true;}; + + //!apply move for the connection moves + template + void applyMove(IngredientsType& ing, const MoveBase& move){}; + + //!apply move for the connection moves + template + void applyMove(IngredientsType& ing, const MoveConnectBase& move); + + //!apply move for the breaking moves + template + void applyMove(IngredientsType& ing, const MoveBreakBase& move); + + //! Synchronize, count the number of reactive sites and reacted bonds + template + void synchronize(IngredientsType& ingredients); - //! Export the relevant functionality for reading bfm-files to the responsible reader object - template - void exportRead(FileImport& fileReader); + //!returns the number of bond made of two reactive monomers + uint32_t getNReactedBonds() const { return BondedReactiveMonomers.size(); }; - //! Export the relevant functionality for writing bfm-files to the responsible writer object - template - void exportWrite(AnalyzerWriteBfmFile& fileWriter) const; - - //! check base move - always true - template - bool checkMove(const IngredientsType& ingredients, const MoveBase& move) const{return true;}; - - //! check base connection move - template - bool checkMove(const IngredientsType& ingredients, const MoveConnectBase& move) const; - - //! check base break move - template - bool checkMove(const IngredientsType& ingredients, const MoveBreakBase& move) const ; - - //! check movebreakreactive - template - bool checkMove(const IngredientsType& ingredients, const MoveBreakReactive& move) const ; - - //!apply move for the connection moves - template - void applyMove(IngredientsType& ing, const MoveBase& move){}; - - //!apply move for the connection moves - template - void applyMove(IngredientsType& ing, const MoveConnectBase& move); - - //!apply move for the breaking moves - template - void applyMove(IngredientsType& ing, const MoveBreakBase& move); - - //! Synchronize, count the number of reactive sites and reacted bonds - template - void synchronize(IngredientsType& ingredients); - - uint32_t getNReactedBonds() const { -// return nReactedBonds; - return BondedReactiveMonomers.size(); - }; + //!returns the total number of reactive monomers capable to form a bond uint32_t getNReactiveSites() const {return nReactiveSites;}; + //!returns the bond table of the reacted reactive monomers. - std::map getBondedMonomers()const {return BondedReactiveMonomers;}; + const std::map& getBondedMonomers()const {return BondedReactiveMonomers;}; + //! returns false if the bond does not exist bool checkReactiveBondExists(uint32_t Mon1, uint32_t Mon2) const { BondPair edge_key(std::min(Mon1,Mon2),std::max(Mon1,Mon2)); return (BondedReactiveMonomers.find(edge_key) != BondedReactiveMonomers.end()); } - //! - std::map getUnreactiveMonomers() const {return UnbondedReactiveMonomers;}; - //! + + //! returns the map of unreacted monomers + const std::map& getUnreactiveMonomers() const {return UnbondedReactiveMonomers;}; + + //!returns the number of reactive monomers capable to form a bond uint32_t getNUnreactedMonomers()const{return UnbondedReactiveMonomers.size();} - //! + + //!returns true if the monomer can be connected to another monomer bool checkCapableFormingBonds(uint32_t MonID )const { return (UnbondedReactiveMonomers.find(MonID) != UnbondedReactiveMonomers.end()); } + //!get extent of reaction double getConversion() const {return (double(nReactedBonds*2))/(double(nReactiveSites));} private: - uint32_t nReactedBonds, nReactiveSites; - //! holds all bonded reactive monomers during simulation - std::map BondedReactiveMonomers; - //! holds the ids of all reactive monomers which can have another bonds - std::map UnbondedReactiveMonomers; - //! -// void addReactiveMonomer(uint32_t MonID, uint32_t value=0){UnbondedReactiveMonomers.emplace(MonID,value);} // adds a new entry if the - void addReactiveMonomer(uint32_t MonID, uint32_t value=0){UnbondedReactiveMonomers[MonID]=value;} // adds a new entry if the - //! - void eraseReactiveMonomer(uint32_t MonID, uint32_t value=0){UnbondedReactiveMonomers.erase(UnbondedReactiveMonomers.find(MonID));} - //!add a bond to the container BondedReactiveMonomers - void addBondedPair(uint32_t Monomer1, uint32_t Monomer2, uint32_t attribute=0){ - BondPair edge_key(std::min(Monomer1,Monomer2),std::max(Monomer1,Monomer2)); - BondedReactiveMonomers[edge_key]=attribute; - } - //!erase a bond from the container BondedReactiveMonomers - void eraseBondedPair(uint32_t Monomer1, uint32_t Monomer2, uint32_t attribute=0){ - BondPair edge_key(std::min(Monomer1,Monomer2),std::max(Monomer1,Monomer2)); - typename std::map::iterator it; - it=BondedReactiveMonomers.find(edge_key); - BondedReactiveMonomers.erase(it); - } - -}; + //!number of bonds from reactive monomers and the total number of reactive monomers + uint32_t nReactedBonds, nReactiveSites; + + //! holds all bonded reactive monomers during simulation + std::map BondedReactiveMonomers; + + //! holds the ids of all reactive monomers which can have another bonds + std::map UnbondedReactiveMonomers; + + //! adds the monomer to the map of unreacted monomers + void addReactiveMonomer(uint32_t MonID, uint32_t value=0){UnbondedReactiveMonomers[MonID]=value;} // adds a new entry if the + //! erase the monomer ID from the map of unreacted monomers + void eraseReactiveMonomer(uint32_t MonID, uint32_t value=0){UnbondedReactiveMonomers.erase(UnbondedReactiveMonomers.find(MonID));} + + //!add a bond to the container BondedReactiveMonomers + void addBondedPair(uint32_t Monomer1, uint32_t Monomer2, uint32_t attribute=0){ + BondPair edge_key(std::min(Monomer1,Monomer2),std::max(Monomer1,Monomer2)); + BondedReactiveMonomers[edge_key]=attribute; + } + + //!erase a bond from the container BondedReactiveMonomers + void eraseBondedPair(uint32_t Monomer1, uint32_t Monomer2, uint32_t attribute=0){ + BondPair edge_key(std::min(Monomer1,Monomer2),std::max(Monomer1,Monomer2)); + typename std::map::iterator it; + it=BondedReactiveMonomers.find(edge_key); + BondedReactiveMonomers.erase(it); + } +}; /////////////////////////////////////////////////////////////////////////////// ////////////////////////// member definitions ///////////////////////////////// /** @@ -310,15 +320,13 @@ class FeatureReactiveBonds : public Feature { * taken care automatically when it becomes necessary.\n * Registered Read-In Commands: * * !reactivity - * * @param fileReader File importer for the bfm-file * @param destination List of Feature to write-in from the read values. * @tparam IngredientsType Features used in the system. See Ingredients. **/ template -void FeatureReactiveBonds::exportRead(FileImport< IngredientsType >& fileReader) -{ - fileReader.registerRead("!reactivity",new ReadReactivity(fileReader.getDestination())); +void FeatureReactiveBonds::exportRead(FileImport< IngredientsType >& fileReader) { + fileReader.registerRead("!reactivity",new ReadReactivity(fileReader.getDestination())); } /** * The function is called by the Ingredients class when an object of type Ingredients @@ -326,13 +334,11 @@ void FeatureReactiveBonds::exportRead(FileImport< IngredientsType >& fileReader) * taken care automatically when it becomes necessary.\n * Registered Write-Out Commands: * * !reactivity - * * @param fileWriter File writer for the bfm-file. */ template -void FeatureReactiveBonds::exportWrite(AnalyzerWriteBfmFile< IngredientsType >& fileWriter) const -{ - fileWriter.registerWrite("!reactivity",new WriteReactivity(fileWriter.getIngredients_())); +void FeatureReactiveBonds::exportWrite(AnalyzerWriteBfmFile< IngredientsType >& fileWriter) const{ + fileWriter.registerWrite("!reactivity",new WriteReactivity(fileWriter.getIngredients_())); } /******************************************************************************/ /** @@ -346,24 +352,18 @@ void FeatureReactiveBonds::exportWrite(AnalyzerWriteBfmFile< IngredientsType >& */ /******************************************************************************/ template -bool FeatureReactiveBonds ::checkMove(const IngredientsType& ingredients, const MoveConnectBase& move) const -{ - uint32_t ID(move.getIndex()); - const typename IngredientsType::molecules_type& molecules=ingredients.getMolecules(); - - //check for maximum number of bonds for the first monomer - if ( molecules.getNumLinks(ID) >= molecules[ID].getNumMaxLinks()) return false; - - uint32_t Neighbor(move.getPartner()); - - //check if neighbor is reactive - if ( !molecules[Neighbor].isReactive() ) return false; - - //check for maximum number of bonds for the second monomer - if ( molecules.getNumLinks(Neighbor) >= molecules[Neighbor].getNumMaxLinks() ) return false; - - //if still here, then the two monomers are allowed to connect - return true; +bool FeatureReactiveBonds ::checkMove(const IngredientsType& ingredients, const MoveConnectBase& move) const { + uint32_t ID(move.getIndex()); + const typename IngredientsType::molecules_type& molecules=ingredients.getMolecules(); + //check for maximum number of bonds for the first monomer + if ( molecules.getNumLinks(ID) >= molecules[ID].getNumMaxLinks()) return false; + uint32_t Neighbor(move.getPartner()); + //check if neighbor is reactive + if ( !molecules[Neighbor].isReactive() ) return false; + //check for maximum number of bonds for the second monomer + if ( molecules.getNumLinks(Neighbor) >= molecules[Neighbor].getNumMaxLinks() ) return false; + //if still here, then the two monomers are allowed to connect + return true; } /******************************************************************************/ /** @@ -377,33 +377,16 @@ bool FeatureReactiveBonds ::checkMove(const IngredientsType& ingredients, const */ /******************************************************************************/ template -bool FeatureReactiveBonds ::checkMove(const IngredientsType& ingredients, const MoveBreakBase& move) const -{ +bool FeatureReactiveBonds ::checkMove(const IngredientsType& ingredients, const MoveBreakBase& move) const { const typename IngredientsType::molecules_type& molecules=ingredients.getMolecules(); //check if neighbor is reactive - uint32_t ID(move.getIndex()); - if ( !molecules[ID].isReactive() ) return false; + uint32_t ID(move.getIndex()); + if ( !molecules[ID].isReactive() ) return false; //check if neighbor is reactive uint32_t Neighbor(move.getPartner()); - if ( !molecules[Neighbor].isReactive() ) return false; - //if still here, then the two monomers are allowed to connect - return true; -} -/******************************************************************************/ -/** - * @fn bool FeatureReactiveBonds ::checkMove(const IngredientsType& ingredients, const MoveBreakBase& move) const - * @brief Returns true for all moves other than the ones that have specialized versions of this function. - * This dummy function is implemented for generality. - * @details it might make a difference for the speed if the order of statements is switched for different systems parameters - * @param [in] ingredients A reference to the IngredientsType - mainly the system - * @param [in] move MoveBreakReactive chooses only reactie monomers - * @return true Always! - */ -/******************************************************************************/ -template -bool FeatureReactiveBonds ::checkMove(const IngredientsType& ingredients, const MoveBreakReactive& move) const -{ - return true; + if ( !molecules[Neighbor].isReactive() ) return false; + //if still here, then the two monomers are allowed to connect + return true; } /******************************************************************************/ /** @@ -415,17 +398,15 @@ bool FeatureReactiveBonds ::checkMove(const IngredientsType& ingredients, const */ /******************************************************************************/ template -void FeatureReactiveBonds ::applyMove(IngredientsType& ing, const MoveConnectBase& move) -{ - nReactedBonds++; - auto MonID(move.getIndex()); - auto Partner(move.getPartner()); - addBondedPair(MonID,Partner,ing.getMolecules().getAge()); - if (ing.getMolecules()[MonID].getNumMaxLinks()==ing.getMolecules().getNumLinks(MonID) ) - eraseReactiveMonomer(MonID); - if (ing.getMolecules()[Partner].getNumMaxLinks()==ing.getMolecules().getNumLinks(Partner) ) - eraseReactiveMonomer(Partner); - +void FeatureReactiveBonds ::applyMove(IngredientsType& ing, const MoveConnectBase& move) { + nReactedBonds++; + auto MonID(move.getIndex()); + auto Partner(move.getPartner()); + addBondedPair(MonID,Partner,ing.getMolecules().getAge()); + if (ing.getMolecules()[MonID].getNumMaxLinks()==ing.getMolecules().getNumLinks(MonID) ) + eraseReactiveMonomer(MonID); + if (ing.getMolecules()[Partner].getNumMaxLinks()==ing.getMolecules().getNumLinks(Partner) ) + eraseReactiveMonomer(Partner); } /******************************************************************************/ /** @@ -437,14 +418,13 @@ void FeatureReactiveBonds ::applyMove(IngredientsType& ing, const MoveConnectBas */ /******************************************************************************/ template -void FeatureReactiveBonds ::applyMove(IngredientsType& ing, const MoveBreakBase& move) -{ - nReactedBonds--; - auto MonID(move.getIndex()); - auto Partner(move.getPartner()); - eraseBondedPair(MonID,Partner); - addReactiveMonomer(MonID,ing.getMolecules().getAge()); - addReactiveMonomer(Partner,ing.getMolecules().getAge()); +void FeatureReactiveBonds ::applyMove(IngredientsType& ing, const MoveBreakBase& move) { + nReactedBonds--; + auto MonID(move.getIndex()); + auto Partner(move.getPartner()); + eraseBondedPair(MonID,Partner); + addReactiveMonomer(MonID,ing.getMolecules().getAge()); + addReactiveMonomer(Partner,ing.getMolecules().getAge()); } /******************************************************************************/ @@ -456,54 +436,44 @@ void FeatureReactiveBonds ::applyMove(IngredientsType& ing, const MoveBreakBase< */ /******************************************************************************/ template -void FeatureReactiveBonds::synchronize(IngredientsType& ingredients) -{ - std::cout << "FeatureReactiveBonds::synchronizing ...\n"; +void FeatureReactiveBonds::synchronize(IngredientsType& ingredients){ + BondedReactiveMonomers.clear(); + UnbondedReactiveMonomers.clear(); + std::cout << "FeatureReactiveBonds::synchronizing ...\n"; nReactedBonds=0; nReactiveSites=0; - for(size_t i = 0 ; i < ingredients.getMolecules().size(); i++ ) - { - if ( ingredients.getMolecules()[i].isReactive() ) - { - addReactiveMonomer(i,ingredients.getMolecules().getAge()); + for(size_t i = 0 ; i < ingredients.getMolecules().size(); i++ ){ + if ( ingredients.getMolecules()[i].isReactive() ){ uint32_t NLinks(ingredients.getMolecules().getNumLinks(i)); uint32_t nIrreversibleBonds=0; - for (uint32_t n = 0 ; n < NLinks ;n++) - { + for (uint32_t n = 0 ; n < NLinks ;n++){ uint32_t neighbor(ingredients.getMolecules().getNeighborIdx(i,n)); if( ingredients.getMolecules()[neighbor].isReactive() ) nReactedBonds++; else - nIrreversibleBonds++; + nIrreversibleBonds++; } if(ingredients.getMolecules()[i].getNumMaxLinks()-ingredients.getMolecules().getNumLinks(i) != 0) - addReactiveMonomer(i,ingredients.getMolecules().getAge()); + addReactiveMonomer(i,ingredients.getMolecules().getAge()); nReactiveSites+=(ingredients.getMolecules()[i].getNumMaxLinks()-nIrreversibleBonds); - } - } - nReactedBonds/=2; // they are counted twice: each monomer counts the bond, but essentially there is only one bond. - std::cout << "Number of reactive bonds: " << nReactedBonds <<"\n" - << "Number of reactive sites: " << nReactiveSites<<"\n" - << "Extent of reaction : " << getConversion() - <first.first); - auto MonID2(it->first.second); - if(ingredients.getMolecules()[MonID1].isReactive() && ingredients.getMolecules()[MonID2].isReactive()) - addBondedPair(MonID1,MonID2,ingredients.getMolecules().getAge()); - } + } } - std::cout << "done\n"; + nReactedBonds/=2; // they are counted twice: each monomer counts the bond, but essentially there is only one bond. + std::cout << "Number of reactive bonds: " << nReactedBonds <<"\n" + << "Number of reactive sites: " << nReactiveSites<<"\n" + << "Extent of reaction : " << getConversion() + <first.first); + auto MonID2(it->first.second); + if(ingredients.getMolecules()[MonID1].isReactive() && ingredients.getMolecules()[MonID2].isReactive()) + addBondedPair(MonID1,MonID2,ingredients.getMolecules().getAge()); + } + } + std::cout << "done\n"; } /////////////////////////////////////////////////////////////////////////////// ///////////////////// member definitions for output /////////////////////////// @@ -517,155 +487,126 @@ void FeatureReactiveBonds::synchronize(IngredientsType& ingredients) template < class IngredientsType > void ReadReactivity::execute() { - //some variables used during reading - //counts the number of reactivity lines in the file - int nReactiveBlocks=0; - int startIndex,stopIndex; - MonomerReactivity reactivity; - //contains the latest line read from file - std::string line; - //used to reset the position of the get pointer after processing the command - std::streampos previous; - //for convenience: get the input stream - std::istream& source=this->getInputStream(); - //for convenience: get the set of monomers - typename IngredientsType::molecules_type& molecules=this->getDestination().modifyMolecules(); - - //go to next line and save the position of the get pointer into streampos previous - getline(source,line); - previous=(source).tellg(); - - //read and process the lines containing the bond vector definition - getline(source,line); - - while(!line.empty() && !((source).fail())){ - - //stop at next Read and set the get-pointer to the position before the Read - if(this->detectRead(line)){ - (source).seekg(previous); - break; - } - - //initialize stringstream with content for ease of processing - std::stringstream stream(line); - - //read vector components - stream>>startIndex; - - //throw exception, if extraction fails - if(stream.fail()){ - std::stringstream messagestream; - messagestream<<"ReadReactivity::execute()\n" - <<"Could not read first index in reactivity line "<findSeparator(stream,'-')){ - - std::stringstream messagestream; - messagestream<<"ReadReactivity::execute()\n" - <<"Wrong definition of reactivity\nCould not find separator \"-\" " - <<"in reactivity definition no "<>stopIndex; - - //throw exception, if extraction fails - if(stream.fail()){ - std::stringstream messagestream; - messagestream<<"ReadReactivity::execute()\n" - <<"Could not read second index in reactivity line "<findSeparator(stream,':')){ - - std::stringstream messagestream; - messagestream<<"ReadReactivity::execute()\n" - <<"Wrong definition of reactivity\nCould not find separator \":\" " - <<"in reactivity definition no "<>reactivity; - //if extraction worked, save the attributes - if(!stream.fail()){ - - //save attributes - for(int n=startIndex;n<=stopIndex;n++) - { - //check if the number of maximum bonds is consistent with the maximum number of bonds given for ingredients - if ( this->getDestination().getMolecules().getMaxConnectivity() >= reactivity.getNumMaxLinks() ) - { - //use n-1 as index, because bfm-files start counting indices at 1 (not 0) - molecules[n-1].setMonomerReactivity(reactivity); -// std::cout << "idx" << n-1 << " reactivity: " << reactivity.isReactive() << " numMaxBonds" << reactivity.getNumMaxLinks() << std::endl; - }else - { - std::stringstream messagestream; - messagestream<<"ReadReactivity::execute()\n" - <<"the numMaxBonds for the current monomer is exceeding the max number \n" - <<"of allowed connectivity for ingredients in "<getInputStream(); + //for convenience: get the set of monomers + typename IngredientsType::molecules_type& molecules=this->getDestination().modifyMolecules(); + //go to next line and save the position of the get pointer into streampos previous + getline(source,line); + previous=(source).tellg(); + //read and process the lines containing the bond vector definition + getline(source,line); + + while(!line.empty() && !((source).fail())){ + //stop at next Read and set the get-pointer to the position before the Read + if(this->detectRead(line)){ + (source).seekg(previous); + break; + } + //initialize stringstream with content for ease of processing + std::stringstream stream(line); + //read vector components + stream>>startIndex; + //throw exception, if extraction fails + if(stream.fail()){ + std::stringstream messagestream; + messagestream<<"ReadReactivity::execute()\n" + <<"Could not read first index in reactivity line "<findSeparator(stream,'-')){ + std::stringstream messagestream; + messagestream<<"ReadReactivity::execute()\n" + <<"Wrong definition of reactivity\nCould not find separator \"-\" " + <<"in reactivity definition no "<>stopIndex; + //throw exception, if extraction fails + if(stream.fail()){ + std::stringstream messagestream; + messagestream<<"ReadReactivity::execute()\n" + <<"Could not read second index in reactivity line "<findSeparator(stream,':')){ + std::stringstream messagestream; + messagestream<<"ReadReactivity::execute()\n" + <<"Wrong definition of reactivity\nCould not find separator \":\" " + <<"in reactivity definition no "<>reactivity; + //if extraction worked, save the attributes + if(!stream.fail()){ + //save attributes + for(int n=startIndex;n<=stopIndex;n++){ + //check if the number of maximum bonds is consistent with the maximum number of bonds given for ingredients + if ( this->getDestination().getMolecules().getMaxConnectivity() >= reactivity.getNumMaxLinks() ) { + //use n-1 as index, because bfm-files start counting indices at 1 (not 0) + molecules[n-1].setMonomerReactivity(reactivity); + }else{ + std::stringstream messagestream; + messagestream<<"ReadReactivity::execute()\n" + <<"the numMaxBonds for the current monomer is exceeding the max number \n" + <<"of allowed connectivity for ingredients in "<::execute()\n" + <<"could not read reactivity information in reactivity definition no "<::execute()\n" - <<"could not read reactivity information in reactivity definition no "< -void WriteReactivity::writeStream(std::ostream& strm) -{ - //for all output the indices are increased by one, because the file-format - //starts counting indices at 1 (not 0) - - //write bfm command - strm<<"!reactivity\n"; - //get reference to monomers - const typename IngredientsType::molecules_type& molecules=this->getSource().getMolecules(); - - size_t nMonomers=molecules.size(); - //reactivity blocks begin with startIndex - size_t startIndex=0; - //counter variable - size_t n=0; - //reactivity to be written (updated in loop below) - MonomerReactivity reactivity=molecules[0].getMonomerReactivity(); - - //write reactivity (blockwise) - while(n::writeStream(std::ostream& strm){ + //for all output the indices are increased by one, because the file-format + //starts counting indices at 1 (not 0) + //write bfm command + strm<<"!reactivity\n"; + //get reference to monomers + const typename IngredientsType::molecules_type& molecules=this->getSource().getMolecules(); + + size_t nMonomers=molecules.size(); + //reactivity blocks begin with startIndex + size_t startIndex=0; + //counter variable + size_t n=0; + //reactivity to be written (updated in loop below) + MonomerReactivity reactivity=molecules[0].getMonomerReactivity(); + + //write reactivity (blockwise) + while(n. + +--------------------------------------------------------------------------------*/ + +#ifndef FEATURE_SYSTEM_INFORMATION_TENDOMER_H +#define FEATURE_SYSTEM_INFORMATION_TENDOMER_H + +#include +#include +#include +#include +#include + + +class FeatureSystemInformationDendrimer:public Feature +{ +public: + + FeatureSystemInformationDendrimer(): generation(0), spacerLength(0), coreFunctionality(0), branchingPointFunctionality(0){}; + + virtual ~FeatureSystemInformationDendrimer(){}; + + //! For all unknown moves: this does nothing + template + bool checkMove(const IngredientsType& ingredientsngredients,const MoveBase& move) const {return true; } + + //! Export the relevant functionality for reading bfm-files to the responsible reader object + template + void exportRead(FileImport & fileReader); + + //! Export the relevant functionality for reading bfm-files to the responsible reader object + template + void exportWrite(AnalyzerWriteBfmFile & filewriter) const; + + //! getter function for dendrimer generation + uint32_t getGeneration() const {return generation;} + //! setter function for dendrimer generation + void setGeneration(uint32_t generation_){generation=generation_;} + + //! getter function for dendrimer spacer length + uint32_t getSpacerLength() const { return spacerLength;} + //! setter function for dendrimer spacer length + void setSpacerLength(uint32_t spacerLength_){spacerLength=spacerLength_;} + + //! getter function for the functionality of branching of the dendrimer focal point + uint32_t getCoreFunctionality() const { return coreFunctionality;} + //! setter function for the functionality of branching of the dendrimer focal point + void setCoreFunctionality(uint32_t coreFunctionality_){coreFunctionality=coreFunctionality_;} + + //! getter function for the branching functionality of the dendrimer branching points except the focal point + uint32_t getBranchingPointFunctionality() const { return branchingPointFunctionality;} + //! setter function for the branching functionality of the dendrimer branching points except the focal point + void setBranchingPointFunctionality(uint32_t branchingPointFunctionality_){branchingPointFunctionality=branchingPointFunctionality_;} + +protected: + uint32_t generation; + uint32_t spacerLength; + uint32_t coreFunctionality; + uint32_t branchingPointFunctionality; + +}; + +/*****************************************************************/ +/** + * @class ReadDendrimerGeneration + * + * @brief Handles BFM-File-Reads \b #!dendrimer_generation + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template < class IngredientsType> +class ReadDendrimerGeneration: public ReadToDestination +{ +public: + ReadDendrimerGeneration(IngredientsType& ingredients):ReadToDestination(ingredients){} + virtual ~ReadDendrimerGeneration(){} + virtual void execute(); +}; + +template +void ReadDendrimerGeneration::execute() +{ + std::cout<<"reading dendrimer generation..."; + + IngredientsType& ingredients=this->getDestination(); + std::istream& source=this->getInputStream(); + + std::string line; + getline(source,line); + uint32_t dGeneration(std::stoi(line)); + std::cout << "#!dendrimer_generation=" << (dGeneration) << std::endl; + + ingredients.setGeneration(dGeneration); + +} +/*****************************************************************/ +/** + * @class ReadDendrimerSpacerLength + * + * @brief Handles BFM-File-Reads \b #!dendrimer_spacer_length + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template < class IngredientsType> +class ReadDendrimerSpacerLength: public ReadToDestination +{ +public: + ReadDendrimerSpacerLength(IngredientsType& ingredients):ReadToDestination(ingredients){} + virtual ~ReadDendrimerSpacerLength(){} + virtual void execute(); +}; + +template +void ReadDendrimerSpacerLength::execute() +{ + std::cout<<"reading dendrimer spacer length..."; + + IngredientsType& ingredients=this->getDestination(); + std::istream& source=this->getInputStream(); + + std::string line; + getline(source,line); + uint32_t dSpacerLength(std::stoi(line)); + std::cout << "#!dendrimer_spacer_length=" << (dSpacerLength) << std::endl; + + ingredients.setSpacerLength(dSpacerLength); +} +/*****************************************************************/ +/** + * @class ReadDendrimerCoreFunctionality + * + * @brief Handles BFM-File-Reads \b #!dendrimer_core_functionality + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template < class IngredientsType> +class ReadDendrimerCoreFunctionality: public ReadToDestination +{ +public: + ReadDendrimerCoreFunctionality(IngredientsType& ingredients):ReadToDestination(ingredients){} + virtual ~ReadDendrimerCoreFunctionality(){} + virtual void execute(); +}; + +template +void ReadDendrimerCoreFunctionality::execute() +{ + std::cout<<"reading dendrimer core functionality..."; + + IngredientsType& ingredients=this->getDestination(); + std::istream& source=this->getInputStream(); + + std::string line; + getline(source,line); + uint32_t dCoreFunct(std::stoi(line)); + std::cout << "#!dendrimer_core_functionality=" << (dCoreFunct) << std::endl; + + ingredients.setCoreFunctionality(dCoreFunct); +} +/*****************************************************************/ +/** + * @class ReadDendrimerBranchingPointFunctionality + * + * @brief Handles BFM-File-Reads \b #!dendrimer_branching_point_functionality + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template < class IngredientsType> +class ReadDendrimerBranchingPointFunctionality: public ReadToDestination +{ +public: + ReadDendrimerBranchingPointFunctionality(IngredientsType& ingredients):ReadToDestination(ingredients){} + virtual ~ReadDendrimerBranchingPointFunctionality(){} + virtual void execute(); +}; + +template +void ReadDendrimerBranchingPointFunctionality::execute() +{ + std::cout<<"reading dendrimer branching point functionality..."; + + IngredientsType& ingredients=this->getDestination(); + std::istream& source=this->getInputStream(); + + std::string line; + getline(source,line); + uint32_t dBraPoFunct(std::stoi(line)); + std::cout << "#!dendrimer_branching_point_functionality=" << (dBraPoFunct) << std::endl; + + ingredients.setBranchingPointFunctionality(dBraPoFunct); +} + +/** + * @details The function is called by the Ingredients class when an object of type Ingredients + * is associated with an object of type FileImport. The export of the Reads is thus + * taken care automatically when it becomes necessary.\n + * Registered Read-In Commands: + * * #!dendrimer_generation + * * #!dendrimer_spacer_length + * * #!dendrimer_core_functionality + * * #!dendrimer_branching_point_functionality + * + * @param fileReader File importer for the bfm-file + * @param destination List of Feature to write-in from the read values. + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +void FeatureSystemInformationDendrimer::exportRead(FileImport< IngredientsType >& fileReader) +{ + fileReader.registerRead("#!dendrimer_generation", new ReadDendrimerGeneration(fileReader.getDestination())); + fileReader.registerRead("#!dendrimer_spacer_length", new ReadDendrimerSpacerLength(fileReader.getDestination())); + fileReader.registerRead("#!dendrimer_core_functionality", new ReadDendrimerCoreFunctionality(fileReader.getDestination())); + fileReader.registerRead("#!dendrimer_branching_point_functionality", new ReadDendrimerBranchingPointFunctionality(fileReader.getDestination())); +} + +/*****************************************************************/ +/** + * @class WriterDendrimerGeneration + * + * @brief Handles BFM-File-Write \b #!dendrimer_generation + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +class WriterDendrimerGeneration:public AbstractWrite +{ +public: + WriterDendrimerGeneration(const IngredientsType& ingredients) + :AbstractWrite(ingredients){this->setHeaderOnly(true);} + + virtual ~WriterDendrimerGeneration(){} + + virtual void writeStream(std::ostream& strm); +}; + +template +void WriterDendrimerGeneration::writeStream(std::ostream& stream) +{ + //get reference to molecules + stream<<"#!dendrimer_generation=" << (this->getSource().getGeneration()) << std::endl<< std::endl; +} +/*****************************************************************/ +/** + * @class WriterDendrimerSpacerLength + * + * @brief Handles BFM-File-Write \b #!dendrimer_spacer_length + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +class WriterDendrimerSpacerLength:public AbstractWrite +{ +public: + WriterDendrimerSpacerLength(const IngredientsType& ingredients) + :AbstractWrite(ingredients){this->setHeaderOnly(true);} + + virtual ~WriterDendrimerSpacerLength(){} + + virtual void writeStream(std::ostream& strm); +}; + +template +void WriterDendrimerSpacerLength::writeStream(std::ostream& stream) +{ + stream<<"#!dendrimer_spacer_length=" << (this->getSource().getSpacerLength()) << std::endl<< std::endl; +} +/*****************************************************************/ +/** + * @class WriterDendrimerCoreFunctionality + * + * @brief Handles BFM-File-Write \b #!dendrimer_core_functionality + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +class WriterDendrimerCoreFunctionality:public AbstractWrite +{ +public: + WriterDendrimerCoreFunctionality(const IngredientsType& ingredients) + :AbstractWrite(ingredients){this->setHeaderOnly(true);} + + virtual ~WriterDendrimerCoreFunctionality(){} + + virtual void writeStream(std::ostream& strm); +}; + +template +void WriterDendrimerCoreFunctionality::writeStream(std::ostream& stream) +{ + stream<<"#!dendrimer_core_functionality=" << (this->getSource().getCoreFunctionality()) << std::endl<< std::endl; +} +/*****************************************************************/ +/** + * @class WriterDendrimerBranchingPointFunctionality + * + * @brief Handles BFM-File-Write \b #!dendrimer_branching_point_functionality + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +class WriterDendrimerBranchingPointFunctionality:public AbstractWrite +{ +public: + WriterDendrimerBranchingPointFunctionality(const IngredientsType& ingredients) + :AbstractWrite(ingredients){this->setHeaderOnly(true);} + + virtual ~WriterDendrimerBranchingPointFunctionality(){} + + virtual void writeStream(std::ostream& strm); +}; + +template +void WriterDendrimerBranchingPointFunctionality::writeStream(std::ostream& stream) +{ + stream<<"#!dendrimer_branching_point_functionality=" << (this->getSource().getBranchingPointFunctionality()) << std::endl<< std::endl; +} +/** + * @details The function is called by the Ingredients class when an object of type Ingredients + * is associated with an object of type AnalyzerWriteBfmFile. The export of the Writes is thus + * taken care automatically when it becomes necessary.\n + * Registered Read-In Commands: + * * #!dendrimer_generation + * * #!dendrimer_spacer_length + * * #!dendrimer_core_functionality + * * #!dendrimer_branching_point_functionality + * + * @param fileReader File importer for the bfm-file + * @param destination List of Feature to write-in from the read values. + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +void FeatureSystemInformationDendrimer::exportWrite(AnalyzerWriteBfmFile< IngredientsType >& filewriter) const +{ + const IngredientsType& source=filewriter.getIngredients_(); + filewriter.registerWrite("#!dendrimer_generation", new WriterDendrimerGeneration(source)); + filewriter.registerWrite("#!dendrimer_spacer_length", new WriterDendrimerSpacerLength(source)); + filewriter.registerWrite("#!dendrimer_core_functionality", new WriterDendrimerCoreFunctionality(source)); + filewriter.registerWrite("#!dendrimer_branching_point_functionality", new WriterDendrimerBranchingPointFunctionality(source)); + +} + +#endif /*FEATURE_SYSTEM_INFORMATION_TENDOMER_H*/ diff --git a/include/LeMonADE/feature/FeatureSystemInformationLinearMeltWithCrosslinker.h b/include/LeMonADE/feature/FeatureSystemInformationLinearMeltWithCrosslinker.h new file mode 100644 index 0000000..09ff3fd --- /dev/null +++ b/include/LeMonADE/feature/FeatureSystemInformationLinearMeltWithCrosslinker.h @@ -0,0 +1,442 @@ +/*-------------------------------------------------------------------------------- + ooo L attice-based | + o\.|./o e xtensible | LeMonADE: An Open Source Implementation of the + o\.\|/./o Mon te-Carlo | Bond-Fluctuation-Model for Polymers +oo---0---oo A lgorithm and | + o/./|\.\o D evelopment | Copyright (C) 2013-2015 by + o/.|.\o E nvironment | LeMonADE Principal Developers + ooo | +---------------------------------------------------------------------------------- + +This file is part of LeMonADE. + +LeMonADE is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +LeMonADE is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with LeMonADE. If not, see . + +--------------------------------------------------------------------------------*/ + +#ifndef FEATURE_SYSTEM_INFORMATION_LINEAR_MELT_WITH_CROSSLINKERH +#define FEATURE_SYSTEM_INFORMATION_LINEAR_MELT_WITH_CROSSLINKERH + +#include +#include +#include +#include +#include +#include + + +class FeatureSystemInformationLinearMeltWithCrosslinker:public Feature +{ +public: + + FeatureSystemInformationLinearMeltWithCrosslinker(){ + nChains=0; + nCrossLinkers=0; + chainLength=0; + functionality=0; + nMonomersPerCrossLink=0; + }; + virtual ~FeatureSystemInformationLinearMeltWithCrosslinker(){}; + + //! For all unknown moves: this does nothing + template + bool checkMove(const IngredientsType& ingredients,const MoveBase& move) const {return true; } + + //! Overloaded for moves of type MoveScMonomer to check for sinusoidal movement + template + bool checkMove(const IngredientsType& ingredients,MoveLocalSc& move) const {return true; } + + //! Export the relevant functionality for reading bfm-files to the responsible reader object + template + void exportRead(FileImport & fileReader); + + //! Export the relevant functionality for reading bfm-files to the responsible reader object + template + void exportWrite(AnalyzerWriteBfmFile & filewriter) const; + + //!return the number of chains + uint32_t getNumberofChains() const { return nChains; } + + //!set the number of chains + void setNumberofChains(uint32_t nChains_){nChains=nChains_;} + + //! return the number of cross linkers + uint32_t getNumberofCrossLinkers() const { return nCrossLinkers; } + + //!set the number of cross linekrs + void setNumberofCrossLinkers(uint32_t nCrossLinkers_){nCrossLinkers=nCrossLinkers_;} + + //! returns the chain lenght + const uint32_t getChainLength() const {return chainLength; } + + //!set the chain length + void setChainLength(uint32_t chainLength_){chainLength=chainLength_;} + + //! get the functionality of the cross linker + uint32_t getFunctionality() const {return functionality;} + + //!set the functionality of cross linker + void setFunctionality(uint32_t functionality_){functionality=functionality_;} + + //!get the number of monomres per cross link + uint32_t getNMonomersPerCrossLink() const { return nMonomersPerCrossLink;} + + //!set the number of monomers per cross linker + void setNMonomersPerCrossLink(uint32_t nMonomersPerCrossLink_){nMonomersPerCrossLink=nMonomersPerCrossLink_;} + +private: + uint32_t nChains; + uint32_t nCrossLinkers; + uint32_t chainLength; + uint32_t functionality; + uint32_t nMonomersPerCrossLink; + +}; + +/*****************************************************************/ +/** + * @class ReadLinearChains + * + * @brief Handles BFM-File-Reads \b #!number_of_linear_chains + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template < class IngredientsType> +class ReadLinearChains: public ReadToDestination +{ +public: + ReadLinearChains(IngredientsType& i):ReadToDestination(i){} + virtual ~ReadLinearChains(){} + virtual void execute(); +}; + +template +void ReadLinearChains::execute() +{ + std::cout<<"reading number of Chains..."; + + uint32_t Chains = 0; + IngredientsType& ingredients=this->getDestination(); + std::istream& source=this->getInputStream(); + + std::string line; + getline(source,line); + Chains = atof(line.c_str()); + std::cout << "#!number_of_linear_chains=" << (Chains) << std::endl; + + ingredients.setNumberofChains(Chains); +} +/*****************************************************************/ +/** + * @class ReadCrossLinkerNumber + * + * @brief Handles BFM-File-Reads \b #!number_of_crosslinkers + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template < class IngredientsType> +class ReadCrossLinkerNumber: public ReadToDestination +{ +public: + ReadCrossLinkerNumber(IngredientsType& i):ReadToDestination(i){} + virtual ~ReadCrossLinkerNumber(){} + virtual void execute(); +}; + +template +void ReadCrossLinkerNumber::execute() +{ + std::cout<<"reading number of Crosslinkers..."; + + uint32_t CrossLinkers = 0; + IngredientsType& ingredients=this->getDestination(); + std::istream& source=this->getInputStream(); + + std::string line; + getline(source,line); + CrossLinkers = atof(line.c_str()); + std::cout << "#!number_of_crosslinkers=" << (CrossLinkers) << std::endl; + + ingredients.setNumberofCrossLinkers(CrossLinkers); +} +/*****************************************************************/ +/** + * @class ReadChainLength + * + * @brief Handles BFM-File-Reads \b #!chainLength + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template < class IngredientsType> +class ReadChainLength: public ReadToDestination +{ +public: + ReadChainLength(IngredientsType& i):ReadToDestination(i){} + virtual ~ReadChainLength(){} + virtual void execute(); +}; + +template +void ReadChainLength::execute() +{ + std::cout<<"reading chain length..."; + + uint32_t chainLength = 0; + IngredientsType& ingredients=this->getDestination(); + std::istream& source=this->getInputStream(); + + std::string line; + getline(source,line); + chainLength = atof(line.c_str()); + std::cout << "#!chainLength=" << (chainLength) << std::endl; + + ingredients.setChainLength(chainLength); +} + +/*****************************************************************/ +/** + * @class ReadFunctionality + * + * @brief Handles BFM-File-Reads \b #!functionality + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template < class IngredientsType> +class ReadFunctionality: public ReadToDestination +{ +public: + ReadFunctionality(IngredientsType& i):ReadToDestination(i){} + virtual ~ReadFunctionality(){} + virtual void execute(); +}; + +template +void ReadFunctionality::execute() +{ + std::cout<<"reading functionality..."; + + uint32_t func = 0; + IngredientsType& ingredients=this->getDestination(); + std::istream& source=this->getInputStream(); + + std::string line; + getline(source,line); + func = atof(line.c_str()); + std::cout << "#!functionality=" << (func) << std::endl; + + ingredients.setFunctionality(func); +} + +/*****************************************************************/ +/** + * @class ReadNMonomersPerCrossLink + * + * @brief Handles BFM-File-Reads \b #!nMonomersPerCrossLink + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template < class IngredientsType> +class ReadNMonomersPerCrossLink: public ReadToDestination +{ +public: + ReadNMonomersPerCrossLink(IngredientsType& i):ReadToDestination(i){} + virtual ~ReadNMonomersPerCrossLink(){} + virtual void execute(); +}; + +template +void ReadNMonomersPerCrossLink::execute() +{ + std::cout<<"reading number of monomers per cross link..."; + + uint32_t crosslinkweight = 0; + IngredientsType& ingredients=this->getDestination(); + std::istream& source=this->getInputStream(); + + std::string line; + getline(source,line); + crosslinkweight = atof(line.c_str()); + std::cout << "#!nMonomersPerCrossLink=" << (crosslinkweight) << std::endl; + + ingredients.setNMonomersPerCrossLink(crosslinkweight); +} + +/** + * @details The function is called by the Ingredients class when an object of type Ingredients + * is associated with an object of type FileImport. The export of the Reads is thus + * taken care automatically when it becomes necessary.\n + * Registered Read-In Commands: + * * #!number_of_linear_chains + * * #!number_of_crosslinkers + * * #!chainLength + * * #!functionality + * * #!nMonomersPerCrossLink + * + * @param fileReader File importer for the bfm-file + * @param destination List of Feature to write-in from the read values. + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +void FeatureSystemInformationLinearMeltWithCrosslinker::exportRead(FileImport< IngredientsType >& fileReader) +{ + fileReader.registerRead("#!number_of_linear_chains", new ReadLinearChains(fileReader.getDestination())); + fileReader.registerRead("#!number_of_crosslinkers", new ReadCrossLinkerNumber(fileReader.getDestination())); + fileReader.registerRead("#!chainLength", new ReadChainLength(fileReader.getDestination())); + fileReader.registerRead("#!functionality", new ReadFunctionality(fileReader.getDestination())); + fileReader.registerRead("#!nMonomersPerCrossLink", new ReadNMonomersPerCrossLink(fileReader.getDestination())); +} + +/*****************************************************************/ +/** + * @class WriterLinearChains + * + * @brief Handles BFM-File-Write \b #!number_of_linear_chains + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +class WriterLinearChains:public AbstractWrite +{ +public: + WriterLinearChains(const IngredientsType& i) + :AbstractWrite(i){this->setHeaderOnly(true);} + // WriteBonds(const IngredientsType& src):AbstractWrite(src){this->setHeaderOnly(true);} + + virtual ~WriterLinearChains(){} + + virtual void writeStream(std::ostream& strm); +}; + +template +void WriterLinearChains::writeStream(std::ostream& stream) +{ + //get reference to molecules + + stream<<"#!number_of_linear_chains=" << (this->getSource().getNumberofChains()) << std::endl<< std::endl; +} +/*****************************************************************/ +/** + * @class WriterCrossLinkerNumber + * + * @brief Handles BFM-File-Write \b #!number_of_linear_chains + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +class WriterCrossLinkerNumber:public AbstractWrite +{ +public: + WriterCrossLinkerNumber(const IngredientsType& i) + :AbstractWrite(i){this->setHeaderOnly(true);} + + virtual ~WriterCrossLinkerNumber(){} + + virtual void writeStream(std::ostream& strm); +}; + +template +void WriterCrossLinkerNumber::writeStream(std::ostream& stream) +{ + stream<<"#!number_of_crosslinkers=" << (this->getSource().getNumberofCrossLinkers()) << std::endl<< std::endl; +} +/*****************************************************************/ +/** + * @class WriterChainLength + * + * @brief Handles BFM-File-Write \b #!chainLength + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +class WriterChainLength:public AbstractWrite +{ +public: + WriterChainLength(const IngredientsType& i) + :AbstractWrite(i){this->setHeaderOnly(true);} + + virtual ~WriterChainLength(){} + + virtual void writeStream(std::ostream& strm); +}; + +template +void WriterChainLength::writeStream(std::ostream& stream) +{ + stream<<"#!chainLength=" << (this->getSource().getChainLength()) << std::endl<< std::endl; +} +/*****************************************************************/ +/** + * @class WriterFunctionality + * + * @brief Handles BFM-File-Write \b #!functionality + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +class WriterFunctionality:public AbstractWrite +{ +public: + WriterFunctionality(const IngredientsType& i) + :AbstractWrite(i){this->setHeaderOnly(true);} + + virtual ~WriterFunctionality(){} + + virtual void writeStream(std::ostream& strm); +}; + +template +void WriterFunctionality::writeStream(std::ostream& stream) +{ + stream<<"#!functionality=" << (this->getSource().getFunctionality()) << std::endl<< std::endl; +} +/*****************************************************************/ +/** + * @class WriterNMonomersPerCrossLink + * + * @brief Handles BFM-File-Write \b #!nMonomersPerCrossLink + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +class WriterNMonomersPerCrossLink:public AbstractWrite +{ +public: + WriterNMonomersPerCrossLink(const IngredientsType& i) + :AbstractWrite(i){this->setHeaderOnly(true);} + + virtual ~WriterNMonomersPerCrossLink(){} + + virtual void writeStream(std::ostream& strm); +}; + +template +void WriterNMonomersPerCrossLink::writeStream(std::ostream& stream) +{ + stream<<"#!nMonomersPerCrossLink=" << (this->getSource().getNMonomersPerCrossLink()) << std::endl<< std::endl; +} +/** + * @details The function is called by the Ingredients class when an object of type Ingredients + * is associated with an object of type AnalyzerWriteBfmFile. The export of the Writes is thus + * taken care automatically when it becomes necessary.\n + * Registered Read-In Commands: + * * #!number_of_linear_chains + * * #!number_of_crosslinkers + * * #!chainLength + * + * @param fileReader File importer for the bfm-file + * @param destination List of Feature to write-in from the read values. + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +void FeatureSystemInformationLinearMeltWithCrosslinker::exportWrite(AnalyzerWriteBfmFile< IngredientsType >& filewriter) const +{ + const IngredientsType& source=filewriter.getIngredients_(); + filewriter.registerWrite("#!number_of_linear_chains", new WriterLinearChains(source)); + filewriter.registerWrite("#!number_of_crosslinkers", new WriterCrossLinkerNumber(source)); + filewriter.registerWrite("#!chainLength", new WriterChainLength(source)); + filewriter.registerWrite("#!functionality", new WriterFunctionality(source)); + filewriter.registerWrite("#!nMonomersPerCrossLink", new WriterNMonomersPerCrossLink(source)); +} + +#endif /*FEATURE_SYSTEM_INFORMATION_LINEAR_MELT_WITH_CROSSLINKERH*/ diff --git a/include/LeMonADE/feature/FeatureSystemInformationRingMelt.h b/include/LeMonADE/feature/FeatureSystemInformationRingMelt.h new file mode 100644 index 0000000..3ca9301 --- /dev/null +++ b/include/LeMonADE/feature/FeatureSystemInformationRingMelt.h @@ -0,0 +1,247 @@ +/*-------------------------------------------------------------------------------- + ooo L attice-based | + o\.|./o e xtensible | LeMonADE: An Open Source Implementation of the + o\.\|/./o Mon te-Carlo | Bond-Fluctuation-Model for Polymers +oo---0---oo A lgorithm and | + o/./|\.\o D evelopment | Copyright (C) 2013-2015 by + o/.|.\o E nvironment | LeMonADE Principal Developers + ooo | +---------------------------------------------------------------------------------- + +This file is part of LeMonADE. + +LeMonADE is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +LeMonADE is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with LeMonADE. If not, see . + +--------------------------------------------------------------------------------*/ + +#ifndef FEATURE_SYSTEM_INFORMATION_RING_MELT_H +#define FEATURE_SYSTEM_INFORMATION_RING_MELT_H + +#include +#include +#include +#include +#include +/**---------------------------------------------------------------------------- + * @file FeatureSystemInformationRingMelt + * @brief Provides the read/write functions for the number of rings and + * nMonomersPerRing + * @details The function getNumRings() returns the number of rings and the + * function getNumMonomersPerRing() the number the monomers per ring. + * There are setter functions for setting these variables. This feature is + * purely for convinience and metadata handling. + * @author Toni Müller + *---------------------------------------------------------------------------*/ + +class FeatureSystemInformationRingMelt:public Feature +{ +public: + + FeatureSystemInformationRingMelt():nRings(0), nMonomersPerRing(0) {}; + + virtual ~FeatureSystemInformationRingMelt(){}; + + //! For all unknown moves: this does nothing + template + bool checkMove(const IngredientsType& ingredients,const MoveBase& move) const {return true; } + + //! Overloaded for moves of type MoveScMonomer to check for sinusoidal movement + template + bool checkMove(const IngredientsType& ingredients,MoveLocalSc& move) const {return true; } + + //! Export the relevant functionality for reading bfm-files to the responsible reader object + template + void exportRead(FileImport & fileReader); + + //! Export the relevant functionality for reading bfm-files to the responsible reader object + template + void exportWrite(AnalyzerWriteBfmFile & filewriter) const; + + //! + const uint32_t getNumRings() const {return nRings;} + //! + void setNumRings(uint32_t nRings_){nRings=nRings_;} + + //! + const uint32_t getNumMonomersPerRing() const { return nMonomersPerRing;} + //! + void setNumMonomersPerRing(uint32_t nMonomersPerRing_){nMonomersPerRing=nMonomersPerRing_;} + +protected: + uint32_t nRings; + uint32_t nMonomersPerRing; + +}; + +/*****************************************************************/ +/** + * @class ReadNumOfRings + * + * @brief Handles BFM-File-Reads \b #!number_of_rings + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template < class IngredientsType> +class ReadNumOfRings: public ReadToDestination +{ +public: + ReadNumOfRings(IngredientsType& i):ReadToDestination(i){} + virtual ~ReadNumOfRings(){} + virtual void execute(); +}; + +template +void ReadNumOfRings::execute() +{ + std::cout<<"reading number of ring..."; + + uint32_t Chains = 0; + IngredientsType& ingredients=this->getDestination(); + std::istream& source=this->getInputStream(); + + std::string line; + getline(source,line); + Chains = atof(line.c_str()); + std::cout << "#!number_of_rings=" << (Chains) << std::endl; + + ingredients.setNumRings(Chains); +} + +/*****************************************************************/ +/** + * @class ReadNumOfMonomersPerRing + * + * @brief Handles BFM-File-Reads \b #!number_of_monomers_per_ring# + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template < class IngredientsType> +class ReadNumOfMonomersPerRing: public ReadToDestination +{ +public: + ReadNumOfMonomersPerRing(IngredientsType& i):ReadToDestination(i){} + virtual ~ReadNumOfMonomersPerRing(){} + virtual void execute(); +}; + +template +void ReadNumOfMonomersPerRing::execute() +{ + std::cout<<"reading ring length..."; + + uint32_t ringLength = 0; + IngredientsType& ingredients=this->getDestination(); + std::istream& source=this->getInputStream(); + + std::string line; + getline(source,line); + ringLength = atof(line.c_str()); + std::cout << "#!number_of_monomers_per_ring=" << (ringLength) << std::endl; + + ingredients.setNumMonomersPerRing(ringLength); +} + +/** + * @details The function is called by the Ingredients class when an object of type Ingredients + * is associated with an object of type FileImport. The export of the Reads is thus + * taken care automatically when it becomes necessary.\n + * Registered Read-In Commands: + * * #!number_of_rings + * * #!number_of_monomers_per_ring + * + * @param fileReader File importer for the bfm-file + * @param destination List of Feature to write-in from the read values. + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +void FeatureSystemInformationRingMelt::exportRead(FileImport< IngredientsType >& fileReader) +{ + fileReader.registerRead("#!number_of_rings", new ReadNumOfRings(fileReader.getDestination())); + fileReader.registerRead("#!number_of_monomers_per_ring", new ReadNumOfMonomersPerRing(fileReader.getDestination())); + + +} + +/*****************************************************************/ +/** + * @class WriterNumOfRings + * + * @brief Handles BFM-File-Write \b #!number_of_rings + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +class WriterNumOfRings:public AbstractWrite +{ +public: + WriterNumOfRings(const IngredientsType& i) + :AbstractWrite(i){this->setHeaderOnly(true);} + // WriteBonds(const IngredientsType& src):AbstractWrite(src){this->setHeaderOnly(true);} + + virtual ~WriterNumOfRings(){} + + virtual void writeStream(std::ostream& strm); +}; + +template +void WriterNumOfRings::writeStream(std::ostream& stream) +{ + //get reference to molecules + + stream<<"#!number_of_rings=" << (this->getSource().getNumRings()) << std::endl<< std::endl; +} + +/*****************************************************************/ +/** + * @class WriterNumOfMonomersPerRing + * + * @brief Handles BFM-File-Write \b #!number_of_monomers_per_ring + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +class WriterNumOfMonomersPerRing:public AbstractWrite +{ +public: + WriterNumOfMonomersPerRing(const IngredientsType& i) + :AbstractWrite(i){this->setHeaderOnly(true);} + + virtual ~WriterNumOfMonomersPerRing(){} + + virtual void writeStream(std::ostream& strm); +}; + +template +void WriterNumOfMonomersPerRing::writeStream(std::ostream& stream) +{ + stream<<"#!number_of_monomers_per_ring=" << (this->getSource().getNumMonomersPerRing()) << std::endl<< std::endl; +} +/** + * @details The function is called by the Ingredients class when an object of type Ingredients + * is associated with an object of type AnalyzerWriteBfmFile. The export of the Writes is thus + * taken care automatically when it becomes necessary.\n + * Registered Read-In Commands: + * * #!number_of_rings + * * #!number_of_monomers_per_ring + * + * @param fileReader File importer for the bfm-file + * @param destination List of Feature to write-in from the read values. + * @tparam IngredientsType Ingredients class storing all system information. + **/ +template +void FeatureSystemInformationRingMelt::exportWrite(AnalyzerWriteBfmFile< IngredientsType >& filewriter) const +{ + const IngredientsType& source=filewriter.getIngredients_(); + filewriter.registerWrite("#!number_of_rings", new WriterNumOfRings(source)); + filewriter.registerWrite("#!number_of_monomers_per_ring", new WriterNumOfMonomersPerRing(source)); + +} + +#endif /*FEATURE_SYSTEM_INFORMATION_RING_MELT_H*/ diff --git a/include/LeMonADE/feature/FeatureSystemInformationTendomer.h b/include/LeMonADE/feature/FeatureSystemInformationTendomer.h index c38bc2b..cc8c6ed 100644 --- a/include/LeMonADE/feature/FeatureSystemInformationTendomer.h +++ b/include/LeMonADE/feature/FeatureSystemInformationTendomer.h @@ -39,12 +39,8 @@ class FeatureSystemInformationTendomer:public Feature { public: - FeatureSystemInformationTendomer(){ - nTendomers=0; - nCrossLinkers=0; - nMonomersPerChain=0; - nLabelsPerTendomerArm=0; - }; + FeatureSystemInformationTendomer(): nTendomers(0), nCrossLinkers(0), nMonomersPerChain(0),nLabelsPerTendomerArm(0){}; + virtual ~FeatureSystemInformationTendomer(){}; //! For all unknown moves: this does nothing @@ -64,22 +60,22 @@ class FeatureSystemInformationTendomer:public Feature void exportWrite(AnalyzerWriteBfmFile & filewriter) const; //! - const uint32_t getNumTendomers() const {return nTendomers;} + uint32_t getNumTendomers() const {return nTendomers;} //! void setNumTendomers(uint32_t nTendomers_){nTendomers=nTendomers_;} //! - const uint32_t getNumCrossLinkers() const { return nCrossLinkers;} + uint32_t getNumCrossLinkers() const { return nCrossLinkers;} //! void setNumCrossLinkers(uint32_t nCrossLinkers_){nCrossLinkers=nCrossLinkers_;} //! - const uint32_t getNumMonomersPerChain() const { return nMonomersPerChain;} + uint32_t getNumMonomersPerChain() const { return nMonomersPerChain;} //! void setNumMonomersPerChain(uint32_t nMonomersPerChain_){nMonomersPerChain=nMonomersPerChain_;} //! - const uint32_t getNumLabelsPerTendomerArm() const { return nLabelsPerTendomerArm;} + uint32_t getNumLabelsPerTendomerArm() const { return nLabelsPerTendomerArm;} //! void setNumLabelsPerTendomerArm(uint32_t nLabelsPerTendomerArm_){nLabelsPerTendomerArm=nLabelsPerTendomerArm_;} diff --git a/include/LeMonADE/updater/UpdaterLipidsRandomInitializer.h b/include/LeMonADE/updater/UpdaterLipidsRandomInitializer.h index 7452d86..74b2e1a 100644 --- a/include/LeMonADE/updater/UpdaterLipidsRandomInitializer.h +++ b/include/LeMonADE/updater/UpdaterLipidsRandomInitializer.h @@ -98,6 +98,7 @@ bool UpdaterLipidsRandomInitializer::execute() // and then create solvent. randomInitializer(move); solventCreator(move, rI=true); + return true; }; /** diff --git a/include/LeMonADE/updater/moves/MoveAddMonomerBase.h b/include/LeMonADE/updater/moves/MoveAddMonomerBase.h index 00b00f7..b086c0a 100644 --- a/include/LeMonADE/updater/moves/MoveAddMonomerBase.h +++ b/include/LeMonADE/updater/moves/MoveAddMonomerBase.h @@ -60,7 +60,7 @@ template class MoveAddMonomerBase:public MoveBase { public: - MoveAddMonomerBase():monomerTag(TagType()),reactivity(false), numMaxLinks(0){}; + MoveAddMonomerBase():monomerTag(TagType()),reactivity(false), numMaxLinks(0), label(0){}; //here come the functions that are implemented by the specialization //! Reset the probability template void init(const IngredientsType& ingredients); diff --git a/include/LeMonADE/updater/moves/MoveBreakReactive.h b/include/LeMonADE/updater/moves/MoveBreakReactive.h index e416d08..bf88196 100644 --- a/include/LeMonADE/updater/moves/MoveBreakReactive.h +++ b/include/LeMonADE/updater/moves/MoveBreakReactive.h @@ -74,13 +74,18 @@ void MoveBreakReactive::init(const IngredientsType& ing) this->resetProbability(); //draw index - auto index(this->randomNumbers.r250_rand32() % (ing.getNReactedBonds())); - auto it(ing.getBondedMonomers().begin()); - std::advance( it, index); - auto BondPair(it->first); - this->setIndex(BondPair.first); - this->setPartner(BondPair.second); - + auto nReactiveBonds(ing.getNReactedBonds()); + if (nReactiveBonds==0) { + this->setIndex(0); + this->setPartner(std::numeric_limits::max()); + }else { + auto index(this->randomNumbers.r250_rand32() % nReactiveBonds); + auto it(ing.getBondedMonomers().cbegin()); + std::advance( it, index); + auto BondPair(it->first); + this->setIndex(BondPair.first); + this->setPartner(BondPair.second); + } } /*****************************************************************************/ diff --git a/include/LeMonADE/updater/moves/MoveConnectScReactive.h b/include/LeMonADE/updater/moves/MoveConnectScReactive.h index f074092..fa4fd96 100644 --- a/include/LeMonADE/updater/moves/MoveConnectScReactive.h +++ b/include/LeMonADE/updater/moves/MoveConnectScReactive.h @@ -100,14 +100,21 @@ void MoveConnectScReactive::init(const IngredientsType& ing) this->resetProbability(); //draw index - auto index(this->randomNumbers.r250_rand32() % (ing.getNUnreactedMonomers())); - auto it(ing.getUnreactiveMonomers().begin()); - std::advance( it, index); - this->setIndex(it->first); - //draw direction - VectorInt3 randomDir(shellPositions[ this->randomNumbers.r250_rand32() % 6]); - this->setDir(randomDir); - this->setPartner(ing.getIdFromLattice(ing.getMolecules()[this->getIndex()]+randomDir) ); + auto nUnreactedMonomers(ing.getNUnreactedMonomers()); + if( nUnreactedMonomers ==0 ) { + this->setIndex(0); + this->setPartner(std::numeric_limits::max() ); + } + else { + auto index(this->randomNumbers.r250_rand32() % nUnreactedMonomers); + auto it (ing.getUnreactiveMonomers().cbegin()); + std::advance( it, index); + this->setIndex(it->first); + //draw direction + VectorInt3 randomDir(shellPositions[ this->randomNumbers.r250_rand32() % 6]); + this->setDir(randomDir); + this->setPartner(ing.getIdFromLattice(ing.getMolecules()[this->getIndex()]+randomDir) ); + } } /*****************************************************************************/ diff --git a/include/LeMonADE/updater/moves/MoveLocalScDiag.h b/include/LeMonADE/updater/moves/MoveLocalScDiag.h index a154fd7..89bda44 100644 --- a/include/LeMonADE/updater/moves/MoveLocalScDiag.h +++ b/include/LeMonADE/updater/moves/MoveLocalScDiag.h @@ -114,7 +114,7 @@ void MoveLocalScDiag::init(const IngredientsType& ing) //draw index this->setIndex( (this->randomNumbers.r250_rand32()) %(ing.getMolecules().size()) ); //draw direction - uint32_t randomDir=this->randomNumbers.r250_rand32() % 18; + uint32_t randomDir(this->randomNumbers.r250_rand32() % 18); this->setDir(steps[randomDir]); @@ -142,7 +142,7 @@ void MoveLocalScDiag::init(const IngredientsType& ing, uint32_t index) throw std::runtime_error("MoveLocalScDiag::init(ing, index): index out of range!"); //draw direction - uint32_t randomDir=this->randomNumbers.r250_rand32() % 18; + uint32_t randomDir(this->randomNumbers.r250_rand32() % 18); this->setDir(steps[randomDir]); diff --git a/include/LeMonADE/utility/DistanceCalculation.h b/include/LeMonADE/utility/DistanceCalculation.h index d237255..896a1e9 100644 --- a/include/LeMonADE/utility/DistanceCalculation.h +++ b/include/LeMonADE/utility/DistanceCalculation.h @@ -41,7 +41,7 @@ along with LeMonADE. If not, see . #include #include -namespace Lemonade +namespace LemonadeDistCalcs { /** diff --git a/include/LeMonADE/utility/RandomNumberGenerators.h b/include/LeMonADE/utility/RandomNumberGenerators.h index 3a5b383..8f6b458 100644 --- a/include/LeMonADE/utility/RandomNumberGenerators.h +++ b/include/LeMonADE/utility/RandomNumberGenerators.h @@ -101,6 +101,9 @@ class RandomNumberGenerators //! randomly seed std:rand() void seedSTDRAND(); void seedSTDRAND( uint32_t seed ); + + //! initializes all provided RNGs with default values + void seedDefaultValuesAll(); #ifdef RANDOMNUMBERGENERATOR_ENABLE_CPP11 //! randomly seed only Mersenne Twister from /dev/urandom diff --git a/src/LeMonADE/utility/RandomNumberGenerators.cpp b/src/LeMonADE/utility/RandomNumberGenerators.cpp index 822f6b1..31efe34 100644 --- a/src/LeMonADE/utility/RandomNumberGenerators.cpp +++ b/src/LeMonADE/utility/RandomNumberGenerators.cpp @@ -216,6 +216,14 @@ void RandomNumberGenerators::seedSTDRAND( uint32_t const seed ) std::srand( seed ); } +void RandomNumberGenerators::seedDefaultValuesAll() +{ + r250Engine->loadDefaultState(); +#ifdef RANDOMNUMBERGENERATOR_ENABLE_CPP11 + seedMT(1); +#endif /*RANDOMNUMBERGENERATOR_ENABLE_CPP11*/ +} + #ifdef RANDOMNUMBERGENERATOR_ENABLE_CPP11 diff --git a/tests/core/TestIngredients.cpp b/tests/core/TestIngredients.cpp index cf03ce1..90e8d5a 100644 --- a/tests/core/TestIngredients.cpp +++ b/tests/core/TestIngredients.cpp @@ -125,7 +125,7 @@ TEST_F(IngredientsTest, synchronize_noargument){ typedef Ingredients < Config1> MyIngredients1; typedef LOKI_TYPELIST_3(FeatureBox, FeatureBondset<>,FeatureExcludedVolumeSc<>) Features2; - typedef ConfigureSystem Config2; + typedef ConfigureSystem Config2; typedef Ingredients < Config2> MyIngredients2; @@ -210,7 +210,7 @@ TEST_F(IngredientsTest, synchronize_withargument){ typedef Ingredients < Config1> MyIngredients1; typedef LOKI_TYPELIST_3(FeatureBox, FeatureBondset<>,FeatureExcludedVolumeSc<>) Features2; - typedef ConfigureSystem Config2; + typedef ConfigureSystem Config2; typedef Ingredients < Config2> MyIngredients2; diff --git a/tests/feature/TestFeatureLinearForce.cpp b/tests/feature/TestFeatureLinearForce.cpp new file mode 100644 index 0000000..d813fe3 --- /dev/null +++ b/tests/feature/TestFeatureLinearForce.cpp @@ -0,0 +1,207 @@ +/*-------------------------------------------------------------------------------- + ooo L attice-based | + o\.|./o e xtensible | LeMonADE: An Open Source Implementation of the + o\.\|/./o Mon te-Carlo | Bond-Fluctuation-Model for Polymers +oo---0---oo A lgorithm and | + o/./|\.\o D evelopment | Copyright (C) 2013-2015 by + o/.|.\o E nvironment | LeMonADE Principal Developers (see AUTHORS) + ooo | +---------------------------------------------------------------------------------- + +This file is part of LeMonADE. + +LeMonADE is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +LeMonADE is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with LeMonADE. If not, see . + +--------------------------------------------------------------------------------*/ + + +#include "gtest/gtest.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +class TestFeatureLinearForce : public ::testing::Test{ +public: + typedef LOKI_TYPELIST_2(FeatureMoleculesIO, FeatureLinearForce ) Features; + typedef ConfigureSystem Config; + typedef Ingredients Ing; + Ing ingredients; + + //redirect cout output + // virtual void SetUp(){ + // originalBuffer=std::cout.rdbuf(); + // std::cout.rdbuf(tempStream.rdbuf()); + // }; + + // //restore original output + // virtual void TearDown(){ + // std::cout.rdbuf(originalBuffer); + // }; + //tension force + const double force=1.212; + //! filename for output + const std::string filename="TestFeatureLinearForce.bfm"; + //set some basic thins + void initIng(){ + //prepare ingredients + ingredients.setBoxX(12); + ingredients.setBoxY(12); + ingredients.setBoxZ(12); + ingredients.setPeriodicX(0); + ingredients.setPeriodicY(0); + ingredients.setPeriodicZ(0); + ingredients.synchronize(); + } +private: + std::streambuf* originalBuffer; + std::ostringstream tempStream; + +}; +TEST_F(TestFeatureLinearForce,SetterGetter){ + ingredients.setAmplitudeForce(force); + EXPECT_EQ(ingredients.getAmplitudeForce(),force); + EXPECT_FALSE(ingredients.isForceOn()); + ingredients.setForceOn(true); + EXPECT_TRUE(ingredients.isForceOn()); +} +TEST_F(TestFeatureLinearForce,WriterReader){ + initIng(); + ingredients.setAmplitudeForce(force); + ingredients.setForceOn(true); + ingredients.modifyMolecules().resize(1); + ingredients.modifyMolecules()[0].setAllCoordinates(6,6,6); + ingredients.synchronize(); + AnalyzerWriteBfmFile writer(filename, ingredients, AnalyzerWriteBfmFile::NEWFILE); + writer.initialize(); + writer.execute(); + + Ing ingredients2; + UpdaterReadBfmFile reader(filename, ingredients2, UpdaterReadBfmFile::READ_LAST_CONFIG_SAVE); + reader.initialize(); + EXPECT_EQ(ingredients2.getAmplitudeForce(),force); + EXPECT_TRUE(ingredients2.isForceOn()); + EXPECT_EQ(0,remove(filename.c_str())); + +} +TEST_F(TestFeatureLinearForce,checkMoveLocalSc){ + ingredients.setAmplitudeForce(2); + ingredients.setForceOn(true); + initIng(); + ingredients.modifyMolecules().resize(3); + ingredients.modifyMolecules()[0].setAllCoordinates(6,6,6); + ingredients.modifyMolecules()[1].setAllCoordinates(6,6,6); + ingredients.modifyMolecules()[2].setAllCoordinates(6,6,6); + ingredients.modifyMolecules()[0].setAttributeTag(1); + ingredients.modifyMolecules()[1].setAttributeTag(4); + ingredients.modifyMolecules()[2].setAttributeTag(5); + EXPECT_NO_THROW(ingredients.synchronize()); + + //seed/reset the globally available random number generators with default values + RandomNumberGenerators rng; + rng.seedDefaultValuesAll(); + + MoveLocalSc move; + //monomer without tag + move.init(ingredients,0,VectorInt3(1,0,0)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + move.init(ingredients,0,VectorInt3(-1,0,0)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + + move.init(ingredients,0,VectorInt3(0,1,0)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + move.init(ingredients,1,VectorInt3(0,-1,0)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + move.init(ingredients,0,VectorInt3(0,0,1)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + move.init(ingredients,0,VectorInt3(0,0,-1)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + //direction where no force is applied on for a taged monomer + //second monomer + move.init(ingredients,1,VectorInt3(0,1,0)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + move.init(ingredients,1,VectorInt3(0,-1,0)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + move.init(ingredients,1,VectorInt3(0,0,1)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + move.init(ingredients,1,VectorInt3(0,0,-1)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + //third monomer + move.init(ingredients,2,VectorInt3(0,1,0)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + move.init(ingredients,2,VectorInt3(0,1,0)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + move.init(ingredients,2,VectorInt3(0,0,1)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + move.init(ingredients,2,VectorInt3(0,0,-1)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + //direction where force is applied on for a taged monomer + + move.init(ingredients,1,VectorInt3(-1,0,0)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + move.init(ingredients,1,VectorInt3( 1,0,0)); + // as we seed with default R250, FeatureBoltzmann returns 0.721772 > 0.13533528 + EXPECT_FALSE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , exp(-2)); + + move.init(ingredients,2,VectorInt3(1,0,0)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , 1.0); + + move.init(ingredients,2,VectorInt3(-1,0,0)); + // as we seed with default R250, FeatureBoltzmann returns 0.983861 > 0.13533528 + EXPECT_FALSE(move.check(ingredients)); + EXPECT_EQ(move.getProbability() , exp(-2)); + +} + + + diff --git a/tests/feature/TestFeatureSystemInformationDendrimer.cpp b/tests/feature/TestFeatureSystemInformationDendrimer.cpp new file mode 100644 index 0000000..dc556a2 --- /dev/null +++ b/tests/feature/TestFeatureSystemInformationDendrimer.cpp @@ -0,0 +1,104 @@ +/*-------------------------------------------------------------------------------- + ooo L attice-based | + o\.|./o e xtensible | LeMonADE: An Open Source Implementation of the + o\.\|/./o Mon te-Carlo | Bond-Fluctuation-Model for Polymers +oo---0---oo A lgorithm and | + o/./|\.\o D evelopment | Copyright (C) 2013-2015 by + o/.|.\o E nvironment | LeMonADE Principal Developers (see AUTHORS) + ooo | +---------------------------------------------------------------------------------- + +This file is part of LeMonADE. + +LeMonADE is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +LeMonADE is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with LeMonADE. If not, see . + +--------------------------------------------------------------------------------*/ + +#include +#include + +#include "gtest/gtest.h" + +#include +#include +#include +#include +#include +#include + +class TestFeatureSystemInformationDendrimer: public ::testing::Test{ +public: + //redirect cout output + virtual void SetUp(){ + originalBuffer=std::cout.rdbuf(); + std::cout.rdbuf(tempStream.rdbuf()); + }; + + //restore original output + virtual void TearDown(){ + std::cout.rdbuf(originalBuffer); + }; + +private: + std::streambuf* originalBuffer; + std::ostringstream tempStream; +}; + + +TEST(TestFeatureSystemInformationDendrimer,ReadWrite) +{ + + typedef LOKI_TYPELIST_1(FeatureSystemInformationDendrimer) Features; + typedef ConfigureSystem Config; + typedef Ingredients IngredientsType; + + IngredientsType ingredients; + + constexpr uint32_t generation(5); + constexpr uint32_t spacerlength(2); + constexpr uint32_t coreFunctionality(4); + constexpr uint32_t branchingPointFunctionality(3); + + ingredients.setGeneration(generation); + ingredients.setSpacerLength(spacerlength); + ingredients.setCoreFunctionality(coreFunctionality); + ingredients.setBranchingPointFunctionality(branchingPointFunctionality); + + EXPECT_NO_THROW(ingredients.synchronize()); + + // Check getter and setter + EXPECT_TRUE(ingredients.getGeneration() == 5); + EXPECT_TRUE(ingredients.getSpacerLength() == 2); + EXPECT_TRUE(ingredients.getCoreFunctionality() == 4); + EXPECT_TRUE(ingredients.getBranchingPointFunctionality() == 3); + + // Check writing/reading to the bfm file + AnalyzerWriteBfmFile bfmWriter("TestFeatureSystemInformationDendrimer.bfm", ingredients); + bfmWriter.initialize(); + bfmWriter.execute(); + bfmWriter.cleanup(); + + IngredientsType ingredientsRead; + + UpdaterReadBfmFile bfmReader("TestFeatureSystemInformationDendrimer.bfm",ingredientsRead,UpdaterReadBfmFile::READ_STEPWISE); + bfmReader.initialize(); + + EXPECT_TRUE(ingredients.getGeneration() == 5); + EXPECT_TRUE(ingredients.getSpacerLength() == 2); + EXPECT_TRUE(ingredients.getCoreFunctionality() == 4); + EXPECT_TRUE(ingredients.getBranchingPointFunctionality() == 3); + + EXPECT_EQ(0,std::remove("TestFeatureSystemInformationDendrimer.bfm")); + +} diff --git a/tests/feature/TestFeatureSystemInformationRingMelt.cpp b/tests/feature/TestFeatureSystemInformationRingMelt.cpp new file mode 100644 index 0000000..0cb08ca --- /dev/null +++ b/tests/feature/TestFeatureSystemInformationRingMelt.cpp @@ -0,0 +1,95 @@ +/*-------------------------------------------------------------------------------- + ooo L attice-based | + o\.|./o e xtensible | LeMonADE: An Open Source Implementation of the + o\.\|/./o Mon te-Carlo | Bond-Fluctuation-Model for Polymers +oo---0---oo A lgorithm and | + o/./|\.\o D evelopment | Copyright (C) 2013-2015 by + o/.|.\o E nvironment | LeMonADE Principal Developers (see AUTHORS) + ooo | +---------------------------------------------------------------------------------- + +This file is part of LeMonADE. + +LeMonADE is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +LeMonADE is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with LeMonADE. If not, see . + +--------------------------------------------------------------------------------*/ + +#include +#include + +#include "gtest/gtest.h" + +#include +#include +#include +#include +#include +#include + +class TestFeatureSystemInformationRingMelt: public ::testing::Test{ +public: + //redirect cout output + virtual void SetUp(){ + originalBuffer=std::cout.rdbuf(); + std::cout.rdbuf(tempStream.rdbuf()); + }; + + //restore original output + virtual void TearDown(){ + std::cout.rdbuf(originalBuffer); + }; + +private: + std::streambuf* originalBuffer; + std::ostringstream tempStream; +}; + +TEST(TestFeatureSystemInformationRingMelt,ReadWrite) +{ + + typedef LOKI_TYPELIST_1(FeatureSystemInformationRingMelt) Features; + typedef ConfigureSystem Config; + typedef Ingredients IngredientsType; + + IngredientsType ingredients; + + constexpr uint32_t nMonomersPerRing(19); + constexpr uint32_t nRings(2); + + ingredients.setNumMonomersPerRing(nMonomersPerRing); + ingredients.setNumRings(nRings); + + EXPECT_NO_THROW(ingredients.synchronize()); + + // Check getter and setter + EXPECT_TRUE(ingredients.getNumMonomersPerRing() == 19); + EXPECT_TRUE(ingredients.getNumRings() == 2); + + // Check writing/reading to the bfm file + AnalyzerWriteBfmFile bfmWriter("TestFeatureSystemsInformationRingMelt.bfm", ingredients); + bfmWriter.initialize(); + bfmWriter.execute(); + bfmWriter.cleanup(); + + IngredientsType ingredientsRead; + + UpdaterReadBfmFile bfmReader("TestFeatureSystemsInformationRingMelt.bfm",ingredientsRead,UpdaterReadBfmFile::READ_STEPWISE); + bfmReader.initialize(); + + EXPECT_TRUE(ingredientsRead.getNumMonomersPerRing() == 19); + EXPECT_TRUE(ingredientsRead.getNumRings() == 2); + + EXPECT_EQ(0,std::remove("TestFeatureSystemsInformationRingMelt.bfm")); + +} diff --git a/tests/feature/TestFeatureSystemInformationTendomer.cpp b/tests/feature/TestFeatureSystemInformationTendomer.cpp new file mode 100644 index 0000000..f9502c7 --- /dev/null +++ b/tests/feature/TestFeatureSystemInformationTendomer.cpp @@ -0,0 +1,103 @@ +/*-------------------------------------------------------------------------------- + ooo L attice-based | + o\.|./o e xtensible | LeMonADE: An Open Source Implementation of the + o\.\|/./o Mon te-Carlo | Bond-Fluctuation-Model for Polymers +oo---0---oo A lgorithm and | + o/./|\.\o D evelopment | Copyright (C) 2013-2015 by + o/.|.\o E nvironment | LeMonADE Principal Developers (see AUTHORS) + ooo | +---------------------------------------------------------------------------------- + +This file is part of LeMonADE. + +LeMonADE is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +LeMonADE is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with LeMonADE. If not, see . + +--------------------------------------------------------------------------------*/ + +#include +#include + +#include "gtest/gtest.h" + +#include +#include +#include +#include +#include +#include + +class TestFeatureSystemInformationTendomer: public ::testing::Test{ +public: + //redirect cout output + virtual void SetUp(){ + originalBuffer=std::cout.rdbuf(); + std::cout.rdbuf(tempStream.rdbuf()); + }; + + //restore original output + virtual void TearDown(){ + std::cout.rdbuf(originalBuffer); + }; + +private: + std::streambuf* originalBuffer; + std::ostringstream tempStream; +}; + +TEST(TestFeatureSystemInformationTendomer,ReadWrite) +{ + + typedef LOKI_TYPELIST_1(FeatureSystemInformationTendomer) Features; + typedef ConfigureSystem Config; + typedef Ingredients IngredientsType; + + IngredientsType ingredients; + + constexpr uint32_t nTendomers(8); + constexpr uint32_t nCrossLinkers(4); + constexpr uint32_t nMonomersPerChain(64); + constexpr uint32_t nLabelsPerTendomerArm(9); + + ingredients.setNumTendomers(nTendomers); + ingredients.setNumCrossLinkers(nCrossLinkers); + ingredients.setNumMonomersPerChain(nMonomersPerChain); + ingredients.setNumLabelsPerTendomerArm(nLabelsPerTendomerArm); + + EXPECT_NO_THROW(ingredients.synchronize()); + + // Check getter and setter + EXPECT_TRUE(ingredients.getNumTendomers() == 8); + EXPECT_TRUE(ingredients.getNumCrossLinkers() == 4); + EXPECT_TRUE(ingredients.getNumMonomersPerChain() == 64); + EXPECT_TRUE(ingredients.getNumLabelsPerTendomerArm() == 9); + + // Check writing/reading to the bfm file + AnalyzerWriteBfmFile bfmWriter("TestFeatureSystemInformationTendomer.bfm", ingredients); + bfmWriter.initialize(); + bfmWriter.execute(); + bfmWriter.cleanup(); + + IngredientsType ingredientsRead; + + UpdaterReadBfmFile bfmReader("TestFeatureSystemInformationTendomer.bfm",ingredientsRead,UpdaterReadBfmFile::READ_STEPWISE); + bfmReader.initialize(); + + EXPECT_TRUE(ingredients.getNumTendomers() == 8); + EXPECT_TRUE(ingredients.getNumCrossLinkers() == 4); + EXPECT_TRUE(ingredients.getNumMonomersPerChain() == 64); + EXPECT_TRUE(ingredients.getNumLabelsPerTendomerArm() == 9); + + EXPECT_EQ(0,std::remove("TestFeatureSystemInformationTendomer.bfm")); + +} diff --git a/tests/updater/TestMoveBreakReactive.cpp b/tests/updater/TestMoveBreakReactive.cpp index 6776c38..2ff1c74 100644 --- a/tests/updater/TestMoveBreakReactive.cpp +++ b/tests/updater/TestMoveBreakReactive.cpp @@ -56,16 +56,16 @@ class TestMoveReactiveBreak: public ::testing::Test{ IngredientsType ingredients; -// //redirect cout output -// virtual void SetUp(){ -// originalBuffer=std::cout.rdbuf(); -// std::cout.rdbuf(tempStream.rdbuf()); -// }; -// -// //restore original output -// virtual void TearDown(){ -// std::cout.rdbuf(originalBuffer); -// }; + //redirect cout output + virtual void SetUp(){ + originalBuffer=std::cout.rdbuf(); + std::cout.rdbuf(tempStream.rdbuf()); + }; + + //restore original output + virtual void TearDown(){ + std::cout.rdbuf(originalBuffer); + }; private: std::streambuf* originalBuffer; diff --git a/tests/updater/TestMoveLocalSc.cpp b/tests/updater/TestMoveLocalSc.cpp index f3b4cd4..fcbdaac 100644 --- a/tests/updater/TestMoveLocalSc.cpp +++ b/tests/updater/TestMoveLocalSc.cpp @@ -318,3 +318,68 @@ TEST_F(TestMoveLocalSc, checkAndApply) EXPECT_EQ(VectorInt3(0,9,8),VectorInt3(ingredients.getMolecules()[1])); } + + + +TEST_F(TestMoveLocalSc, entangledRings) +{ + // starting here with a new instance of ingredients! + // class member lifetime is only one testcase! + ingredients.setBoxX(128); + ingredients.setBoxY(32); + ingredients.setBoxZ(32); + ingredients.setPeriodicX(false); + ingredients.setPeriodicY(false); + ingredients.setPeriodicZ(false); + ingredients.modifyBondset().addBFMclassicBondset(); + + ingredients.modifyMolecules().addMonomer(4,8,8); + ingredients.modifyMolecules().addMonomer(7,9,8); + ingredients.modifyMolecules().addMonomer(6,12,8); + ingredients.modifyMolecules().addMonomer(3,11,8); + ingredients.modifyMolecules().connect(0,1); + ingredients.modifyMolecules().connect(1,2); + ingredients.modifyMolecules().connect(2,3); + ingredients.modifyMolecules().connect(3,0); + + ingredients.modifyMolecules().addMonomer(5,10,8); + ingredients.modifyMolecules().addMonomer(3,9,10); + ingredients.modifyMolecules().addMonomer(1,10,8); + ingredients.modifyMolecules().addMonomer(3,9,6); + ingredients.modifyMolecules().connect(4,5); + ingredients.modifyMolecules().connect(5,6); + ingredients.modifyMolecules().connect(6,7); + ingredients.modifyMolecules().connect(7,4); + ingredients.synchronize(); + MoveLocalSc move; + // std::string filename("TestMoveLocalScEntangledRing.bfm"); + // AnalyzerWriteBfmFile BfmWriter(filename, ingredients, AnalyzerWriteBfmFile::NEWFILE); + // BfmWriter.initialize(); + for (uint32_t j=0; j < 100; j++){ + for(uint32_t n=0;n<100;n++){ + for(size_t m=0;m=4 ) //prefer positive x direction + { + move.multiplyProbability(0.2); + } + else if( move.getDir().getX() == 1 && move.getIndex() <4 ) //prefer positive x direction + { + move.multiplyProbability(0.2); + } + if(move.check(ingredients)==true) + move.apply(ingredients); + } + ingredients.modifyMolecules().setAge(ingredients.getMolecules().getAge()+100); + } + ingredients.synchronize(); + // BfmWriter.execute(); + } + // BfmWriter.cleanup(); + EXPECT_EQ(ingredients.getMolecules()[0].getVector3D().getX()-ingredients.getMolecules()[4].getVector3D().getX(),-1 ); + EXPECT_EQ(ingredients.getMolecules()[1].getVector3D().getX()-ingredients.getMolecules()[5].getVector3D().getX(), 4 ); + EXPECT_EQ(ingredients.getMolecules()[2].getVector3D().getX()-ingredients.getMolecules()[6].getVector3D().getX(), 5 ); + EXPECT_EQ(ingredients.getMolecules()[3].getVector3D().getX()-ingredients.getMolecules()[7].getVector3D().getX(), 0 ); + + // remove(filename.c_str()); +} \ No newline at end of file diff --git a/tests/updater/TestMoveLocalScDiag.cpp b/tests/updater/TestMoveLocalScDiag.cpp new file mode 100644 index 0000000..1018009 --- /dev/null +++ b/tests/updater/TestMoveLocalScDiag.cpp @@ -0,0 +1,361 @@ +/*-------------------------------------------------------------------------------- + ooo L attice-based | + o\.|./o e xtensible | LeMonADE: An Open Source Implementation of the + o\.\|/./o Mon te-Carlo | Bond-Fluctuation-Model for Polymers +oo---0---oo A lgorithm and | + o/./|\.\o D evelopment | Copyright (C) 2013-2015 by + o/.|.\o E nvironment | LeMonADE Principal Developers (see AUTHORS) + ooo | +---------------------------------------------------------------------------------- + +This file is part of LeMonADE. + +LeMonADE is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +LeMonADE is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with LeMonADE. If not, see . + +--------------------------------------------------------------------------------*/ + +/*****************************************************************************/ +/** + * @file + * @brief Tests for the class MoveLocalSc + * */ +/*****************************************************************************/ + +#include "gtest/gtest.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +class TestMoveLocalScDiag: public ::testing::Test{ +public: + typedef LOKI_TYPELIST_4(FeatureBoltzmann, FeatureMoleculesIO, FeatureFixedMonomers, FeatureExcludedVolumeSc >) Features; + typedef ConfigureSystem Config; + typedef Ingredients IngredientsType; + + IngredientsType ingredients; + const IngredientsType& getIngredients() const {return ingredients;} + TestMoveLocalScDiag () { + //perpendicular moves + steps[0]=VectorInt3(1,0,0); + steps[1]=VectorInt3(-1,0,0); + steps[2]=VectorInt3(0,1,0); + steps[3]=VectorInt3(0,-1,0); + steps[4]=VectorInt3(0,0,1); + steps[5]=VectorInt3(0,0,-1); + //diagonal moves + steps[6]=VectorInt3(0,1,1); + steps[7]=VectorInt3(0,-1,1); + steps[8]=VectorInt3(0,1,-1); + steps[9]=VectorInt3(0,-1,-1); + steps[10]=VectorInt3(1,0,1); + steps[11]=VectorInt3(1,0,-1); + steps[12]=VectorInt3(-1,0,1); + steps[13]=VectorInt3(-1,0,-1); + steps[14]=VectorInt3(1,1,0); + steps[15]=VectorInt3(1,-1,0); + steps[16]=VectorInt3(-1,1,0); + steps[17]=VectorInt3(-1,-1,0); + } + //redirect cout output + virtual void SetUp(){ + originalBuffer=std::cout.rdbuf(); + std::cout.rdbuf(tempStream.rdbuf()); + }; + + //restore original output + virtual void TearDown(){ + std::cout.rdbuf(originalBuffer); + }; + VectorInt3 steps[18]; +private: + std::streambuf* originalBuffer; + std::ostringstream tempStream; + +}; + +TEST_F(TestMoveLocalScDiag, initialiseSetterGetter) +{ + ingredients.setBoxX(16); + ingredients.setBoxY(16); + ingredients.setBoxZ(16); + ingredients.setPeriodicX(true); + ingredients.setPeriodicY(true); + ingredients.setPeriodicZ(true); + ingredients.modifyBondset().addBFMclassicBondset(); + ingredients.modifyMolecules().addMonomer(8,8,8); + + EXPECT_NO_THROW(ingredients.synchronize()); + EXPECT_EQ(1,ingredients.getMolecules().size()); + + MoveLocalScDiag move; + + // ######################################################################## // + // use empty init interface: dice a random monomer and a random move direction + move.init(getIngredients()); + EXPECT_EQ(1.0,move.getProbability()); + EXPECT_EQ(0,move.getIndex()); + EXPECT_TRUE (move.getDir()*move.getDir() == 1 + || move.getDir()*move.getDir() == 2); + + //change probability + move.multiplyProbability(0.5); + + //add a new monomer, check if init changes properties correctly + ingredients.modifyMolecules().addMonomer(4,8,8); + EXPECT_NO_THROW(ingredients.synchronize()); + EXPECT_EQ(2,ingredients.getMolecules().size()); + + move.init(getIngredients()); + EXPECT_EQ(1.0,move.getProbability()); + EXPECT_TRUE((0==move.getIndex()) || (1==move.getIndex())); + EXPECT_TRUE (move.getDir()*move.getDir() == 1 + || move.getDir()*move.getDir() == 2); + + + // ######################################################################## // + // use index init interface: set the index and dice a random move direction + + EXPECT_NO_THROW(move.init(getIngredients(),0)); + EXPECT_EQ(1.0,move.getProbability()); + EXPECT_EQ(0,move.getIndex()); + EXPECT_TRUE (move.getDir()*move.getDir() == 1 + || move.getDir()*move.getDir() == 2); + //change probability + move.multiplyProbability(0.5); + + EXPECT_EQ(2,ingredients.getMolecules().size()); + EXPECT_NO_THROW(move.init(getIngredients(),1)); + EXPECT_EQ(1.0,move.getProbability()); + EXPECT_EQ(1,move.getIndex()); + EXPECT_TRUE (move.getDir()*move.getDir() == 1 + || move.getDir()*move.getDir() == 2); + + //check wrong index by initialize + EXPECT_ANY_THROW(move.init(getIngredients(),ingredients.getMolecules().size())); + EXPECT_ANY_THROW(move.init(getIngredients(),2)); // ( =same as molecules.size() ) + EXPECT_ANY_THROW(move.init(getIngredients(),-1)); + EXPECT_ANY_THROW(move.init(getIngredients(),68468468)); + + // ######################################################################## // + // use direction init interface: dice an index and set the move direction + for(auto direction : steps ){ + EXPECT_NO_THROW(move.init(getIngredients(),direction)); + EXPECT_EQ(1.0,move.getProbability()); + EXPECT_TRUE((0==move.getIndex()) || (1==move.getIndex())); + EXPECT_EQ(direction,move.getDir()); + //change probability + move.multiplyProbability(0.5); + } + VectorInt3 direction(2,0,0); + EXPECT_ANY_THROW(move.init(getIngredients(),direction)); + direction.setAllCoordinates(0,-2,0); + EXPECT_ANY_THROW(move.init(getIngredients(),direction)); + + // ######################################################################## // + // use direction and index init interface: set index and the move direction + //check all possible directions + + for(auto index=0; index<2;index++){ + for(auto direction : steps ){ + EXPECT_NO_THROW(move.init(getIngredients(),index,direction)); + EXPECT_EQ(1.0,move.getProbability()); + EXPECT_EQ(index,move.getIndex()); + EXPECT_EQ(direction,move.getDir()); + //change probability + move.multiplyProbability(0.5); + } + } + + //check some forbidden directions and idicees + EXPECT_ANY_THROW(move.init(getIngredients(),2,direction)); + EXPECT_ANY_THROW(move.init(getIngredients(),-1,direction)); + direction.setAllCoordinates(2,0,0); + EXPECT_ANY_THROW(move.init(getIngredients(),1,direction)); + direction.setAllCoordinates(1,-1,1); + EXPECT_ANY_THROW(move.init(getIngredients(),1,direction)); + EXPECT_ANY_THROW(move.init(getIngredients(),2,direction)); + +} + +TEST_F(TestMoveLocalScDiag, checkAndApply) +{ + // starting here with a new instance of ingredients! + // class member lifetime is only one testcase! + ingredients.setBoxX(16); + ingredients.setBoxY(16); + ingredients.setBoxZ(16); + ingredients.setPeriodicX(false); + ingredients.setPeriodicY(true); + ingredients.setPeriodicZ(true); + ingredients.modifyBondset().addBFMclassicBondset(); + ingredients.modifyMolecules().addMonomer(2,8,8); + ingredients.modifyMolecules().addMonomer(0,8,8); + + EXPECT_NO_THROW(ingredients.synchronize()); + EXPECT_EQ(2,ingredients.getMolecules().size()); + + MoveLocalScDiag move; + + // ################################# // + //check move with FeatureExcludedVolumeSc: + VectorInt3 direction(1,0,0); + EXPECT_NO_THROW(move.init(getIngredients(),1,direction)); + EXPECT_FALSE(move.check(ingredients)); + + direction.setAllCoordinates(1,1,0); + EXPECT_NO_THROW(move.init(getIngredients(),1,direction)); + EXPECT_FALSE(move.check(ingredients)); + + direction.setAllCoordinates(1,0,1); + EXPECT_NO_THROW(move.init(getIngredients(),1,direction)); + EXPECT_FALSE(move.check(ingredients)); + + direction.setAllCoordinates(1,-1,0); + EXPECT_NO_THROW(move.init(getIngredients(),1,direction)); + EXPECT_FALSE(move.check(ingredients)); + + direction.setAllCoordinates(1,1,0); + EXPECT_NO_THROW(move.init(getIngredients(),0,direction)); + EXPECT_TRUE(move.check(ingredients)); + move.apply(ingredients); + EXPECT_NO_THROW(move.init(getIngredients(),1,direction)); + EXPECT_TRUE(move.check(ingredients)); + move.apply(ingredients); + + direction.setAllCoordinates(0,-1,1); + EXPECT_NO_THROW(move.init(getIngredients(),0,direction)); + EXPECT_TRUE(move.check(ingredients)); + move.apply(ingredients); + EXPECT_NO_THROW(move.init(getIngredients(),1,direction)); + EXPECT_TRUE(move.check(ingredients)); + move.apply(ingredients); + + direction.setAllCoordinates(0,1,-1); + EXPECT_NO_THROW(move.init(getIngredients(),1,direction)); + EXPECT_TRUE(move.check(ingredients)); + move.apply(ingredients); + EXPECT_NO_THROW(move.init(getIngredients(),0,direction)); + EXPECT_TRUE(move.check(ingredients)); + move.apply(ingredients); + + direction.setAllCoordinates(0,0,-1); + EXPECT_NO_THROW(move.init(getIngredients(),0,direction)); + EXPECT_TRUE(move.check(ingredients)); + EXPECT_NO_THROW(move.init(getIngredients(),1,direction)); + EXPECT_TRUE(move.check(ingredients)); + + direction.setAllCoordinates(1,0,1); + EXPECT_NO_THROW(move.init(getIngredients(),0,direction)); + EXPECT_TRUE(move.check(ingredients)); + move.apply(ingredients); + // now monomers are at positions + + // ################################# // + //check move with FeatureMoleculesIO: + //bondset: + ingredients.modifyMolecules().connect(0,1); + direction.setAllCoordinates(1,-1,0); + EXPECT_NO_THROW(move.init(getIngredients(),0,direction)); + EXPECT_FALSE(move.check(ingredients)); + + direction.setAllCoordinates(-1,-1,0); + EXPECT_NO_THROW(move.init(getIngredients(),0,direction)); + EXPECT_TRUE(move.check(ingredients)); + move.apply(ingredients); + EXPECT_EQ(VectorInt3(3,8,9),VectorInt3(ingredients.getMolecules()[0])); + EXPECT_EQ(VectorInt3(1,9,8),VectorInt3(ingredients.getMolecules()[1])); + // now monomers are at positions 2,9,9 and 0,9,9 + + //nonperiodic wall + direction.setAllCoordinates(-1,0,1); + EXPECT_NO_THROW(move.init(getIngredients(),1,direction)); + EXPECT_TRUE(move.check(ingredients)); + move.apply(ingredients); + direction.setAllCoordinates(-1,0,1); + EXPECT_NO_THROW(move.init(getIngredients(),1,direction)); + EXPECT_FALSE(move.check(ingredients)); +} +TEST_F(TestMoveLocalScDiag, unentangledRings) +{ + // starting here with a new instance of ingredients! + // class member lifetime is only one testcase! + ingredients.setBoxX(128); + ingredients.setBoxY(32); + ingredients.setBoxZ(32); + ingredients.setPeriodicX(false); + ingredients.setPeriodicY(false); + ingredients.setPeriodicZ(false); + ingredients.modifyBondset().addBFMclassicBondset(); + + ingredients.modifyMolecules().addMonomer(4,8,8); + ingredients.modifyMolecules().addMonomer(7,9,8); + ingredients.modifyMolecules().addMonomer(6,12,8); + ingredients.modifyMolecules().addMonomer(3,11,8); + ingredients.modifyMolecules().connect(0,1); + ingredients.modifyMolecules().connect(1,2); + ingredients.modifyMolecules().connect(2,3); + ingredients.modifyMolecules().connect(3,0); + + ingredients.modifyMolecules().addMonomer(5,10,8); + ingredients.modifyMolecules().addMonomer(3,9,10); + ingredients.modifyMolecules().addMonomer(1,10,8); + ingredients.modifyMolecules().addMonomer(3,9,6); + ingredients.modifyMolecules().connect(4,5); + ingredients.modifyMolecules().connect(5,6); + ingredients.modifyMolecules().connect(6,7); + ingredients.modifyMolecules().connect(7,4); + ingredients.synchronize(); + MoveLocalScDiag move; + // std::string filename("TestMoveLocalScDiag.bfm"); + // AnalyzerWriteBfmFile BfmWriter(filename, ingredients, AnalyzerWriteBfmFile::NEWFILE); + // BfmWriter.initialize(); + for (uint32_t j=0; j < 100; j++){ + for(uint32_t n=0;n<100;n++){ + for(size_t m=0;m=4 ) //prefer positive x direction + { + move.multiplyProbability(0.2); + } + else if( move.getDir().getX() == 1 && move.getIndex() <4 ) //prefer positive x direction + { + move.multiplyProbability(0.2); + } + if(move.check(ingredients)==true) + move.apply(ingredients); + } + ingredients.modifyMolecules().setAge(ingredients.getMolecules().getAge()+100); + } + ingredients.synchronize(); + // BfmWriter.execute(); + } + // BfmWriter.cleanup(); + VectorDouble3 COM1(0.,0.,0.),COM2(0.,0.,0.); + for (auto i=0; i < 4 ; i++) + COM1+=ingredients.getMolecules()[i].getVector3D(); + for (auto i=4; i < 8 ; i++) + COM2+=ingredients.getMolecules()[i].getVector3D(); + COM1.setX(COM1.getX()/4.); + COM2.setX(COM2.getX()/4.); + EXPECT_GE(COM2.getX()-COM1.getX(),64); + // remove(filename.c_str()); +} diff --git a/tests/utility/TestDistanceCalculation.cpp b/tests/utility/TestDistanceCalculation.cpp index b832733..9b9ae3f 100644 --- a/tests/utility/TestDistanceCalculation.cpp +++ b/tests/utility/TestDistanceCalculation.cpp @@ -32,7 +32,7 @@ along with LeMonADE. If not, see . #include #include -using namespace Lemonade; +using namespace LemonadeDistCalcs; class TestDistanceCalculation: public ::testing::Test{ public: