├── .gitignore ├── Dockerfile ├── MSDParser ├── MSDParserfwd.h ├── MSDParserDefines.h ├── MSDParser.h ├── ObjectParser.h └── FileReader.h ├── RunSection ├── RunSectionfwd.h ├── Actions │ ├── ActionAddScalar.h │ ├── ActionScaleVector.h │ ├── ActionMultiplyScalar.h │ ├── ActionAddVector.h │ ├── ActionRotateVector.h │ ├── ActionFibonacciSphere.h │ ├── ActionLogSpace.h │ ├── ActionAddScalar.cpp │ ├── ActionMultiplyScalar.cpp │ ├── ActionScaleVector.cpp │ ├── ActionAddVector.cpp │ └── ActionLogSpace.cpp ├── Tasks │ ├── TaskStaticSSPump.h │ ├── TaskStaticHSSymmetricDecay.h │ ├── TaskStaticSSTimeEvo.h │ ├── TaskPeriodicSSTimeEvo.h │ ├── TaskStaticRPOnlyHSSymDec.h │ ├── TaskStaticHSDirectSpectra.h │ ├── TaskGammaCompute.h │ ├── TaskStaticSSRelaxation.h │ ├── TaskActionSpectrumHistogram.h │ ├── TaskStaticSS.h │ ├── TaskStaticSSCIDNP.h │ ├── TaskMultiStaticSS.h │ ├── TaskStaticHSStochYieldsSymmUncoupled.h │ ├── TaskStaticHSDirectYieldsSymmUncoupled.h │ ├── TaskStaticHSStochTimeEvoSymmUncoupled.h │ ├── TaskStaticHSDirectTimeEvoSymmUncoupled.h │ ├── TaskStaticHSDirectYields.h │ ├── TaskStaticHSStochTimeEvo.h │ ├── TaskStaticHSDirectTimeEvo.h │ ├── TaskMultiStaticSSTimeEvoSpectra.h │ ├── TaskHamiltonianEigenvalues.h │ ├── TaskDynamicHSDirectSpectra.h │ ├── TaskDynamicHSStochYields.h │ ├── TaskDynamicHSDirectYields.h │ ├── TaskDynamicHSStochTimeEvo.h │ ├── TaskStaticSSNakajimaZwanzigTimeEvo.h │ ├── TaskDynamicHSDirectTimeEvo.h │ ├── TaskMultiStaticSSTimeEvo.h │ ├── TaskStaticSSNakajimaZwanzig.h │ ├── TaskStaticSSRedfieldTimeEvo.h │ ├── TaskActionSpectrumHistogramRPOnlyDec.h │ ├── TaskMultiStaticSSNakajimaZwanzigTimeEvo.h │ ├── TaskDynamicHSTimeEvo.h │ ├── TaskStaticSSRedfieldTimeEvoSparse.h │ ├── TaskPeriodicHSTimeEvo.h │ ├── TaskStaticSSRedfield.h │ ├── TaskStaticHSStochYields.h │ ├── TaskStaticSSRedfieldSparse.h │ ├── TaskStaticSSSpectra.h │ ├── TaskMultiStaticSSRedfieldTimeEvo.h │ ├── TaskStaticSSSpectraNakajimaZwanzig.h │ ├── TaskStaticRPOnlyHSSymDecRedfield.h │ ├── TaskMultiDynamicHSTimeEvo.h │ ├── TaskStaticSSPowderSpectra.h │ └── TaskMultiRadicalPairSSTimeEvo.h ├── RunSectionDefines.h ├── OutputHandler.h ├── Settings.h ├── Action.h ├── ActionTarget.h ├── RunSection.h └── BasicTask.h ├── SpinAPI ├── Operator.h ├── SpinAPIfwd.h ├── StandardOutput.h ├── Trajectory.h ├── SubSystem.h ├── SpinAPIDefines.h ├── Function.h ├── Transition.h └── Pulse.h ├── .github └── workflows │ ├── c-cpp.yml │ ├── docker-build-env.yml │ └── docker-molspin.yml ├── Tests ├── tests_utility.cpp └── testmain.cpp ├── Example ├── magnetoreception │ └── timeevolution │ │ ├── example_2.msd │ │ ├── example_2_5_ps.msd │ │ ├── example_2_50_ps.msd │ │ ├── example_2_500_ps.msd │ │ └── example_2_1_ns.msd └── performance_redfield │ ├── example_1.msd │ └── example_3.msd └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore the executable (not be necessary with out-of-source build) 2 | /molspin 3 | /molspin-superlu 4 | /Tests/molspintest 5 | 6 | # Ignore all binaries 7 | *.o 8 | 9 | # Ignore output data and logfiles 10 | *.dat 11 | *.log 12 | 13 | # Ignore user-specific settings 14 | CMakeLists.txt.user 15 | build 16 | .idea 17 | .vscode 18 | *.Identifier 19 | 20 | #Eigen-Free branch 21 | Vendor/ 22 | 23 | #ignore personal msd files 24 | *.py 25 | *.csv 26 | rp*.msd 27 | CISS*.msd 28 | FWW* 29 | *.zip 30 | msd-files/ 31 | *.out 32 | python/ 33 | 34 | #ignore vscode workspase files 35 | MolSpin.code-workspace 36 | MolSpin copy.code-workspace 37 | makefile 38 | 39 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM debian:13 AS build-env 2 | 3 | RUN ln -fs /usr/share/zoneinfo/Europe/Berlin /etc/localtime && \ 4 | apt update && \ 5 | DEBIAN_FRONTEND=noninteractive apt install -y libblas-dev libboost-dev libopenblas-dev cmake gcc make build-essential curl 6 | 7 | WORKDIR /tmp/ 8 | RUN curl -X GET -L -o libarmadillo.tar.xz https://sourceforge.net/projects/arma/files/armadillo-12.8.4.tar.xz/download && \ 9 | tar -xJf /tmp/libarmadillo.tar.xz && \ 10 | cd armadillo-12.8.4 && \ 11 | mkdir build && \ 12 | cd build && \ 13 | cmake -D OPENBLAS_PROVIDES_LAPACK=true .. && \ 14 | make -j 2 && \ 15 | make install 16 | 17 | WORKDIR /root 18 | 19 | FROM build-env 20 | 21 | COPY . . 22 | 23 | RUN make -j 16 24 | 25 | RUN cp molspin /usr/bin 26 | 27 | RUN rm -rf root/* 28 | 29 | ENTRYPOINT ["molspin"] -------------------------------------------------------------------------------- /MSDParser/MSDParserfwd.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ForwardDeclarations (MSDParser Module) 3 | // ------------------ 4 | // Forward declarations of classes etc. to decrease file inter- 5 | // dependencies and speedup compilation time. 6 | // 7 | // NOTE: Make sure this file is included AFTER the other includes! 8 | // 9 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 10 | // (c) 2025 Quantum Biology and Computational Physics Group. 11 | // See LICENSE.txt for license information. 12 | ///////////////////////////////////////////////////////////////////////// 13 | #ifndef MOD_MSDParser_ForwardDeclarations 14 | #define MOD_MSDParser_ForwardDeclarations 15 | 16 | namespace MSDParser 17 | { 18 | #ifndef MOD_MSDParser_MSDParser 19 | class MSDParser; 20 | #endif 21 | 22 | #ifndef MOD_MSDParser_ObjectParser 23 | class ObjectParser; 24 | #endif 25 | } 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /RunSection/RunSectionfwd.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ForwardDeclarations (MSDParser Module) 3 | // ------------------ 4 | // Forward declarations of classes etc. to decrease file inter- 5 | // dependencies and speedup compilation time. 6 | // 7 | // NOTE: Make sure this file is included AFTER the other includes! 8 | // 9 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 10 | // (c) 2025 Quantum Biology and Computational Physics Group. 11 | // See LICENSE.txt for license information. 12 | ///////////////////////////////////////////////////////////////////////// 13 | #ifndef MOD_RunSection_ForwardDeclarations 14 | #define MOD_RunSection_ForwardDeclarations 15 | 16 | namespace RunSection 17 | { 18 | #ifndef MOD_RunSection_RunSection 19 | class RunSection; 20 | #endif 21 | 22 | #ifndef MOD_RunSection_BasicTask 23 | class BasicTask; 24 | #endif 25 | 26 | #ifndef MOD_RunSection_Action 27 | class Action; 28 | #endif 29 | 30 | #ifndef MOD_RunSection_Settings 31 | class Settings; 32 | #endif 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /RunSection/Actions/ActionAddScalar.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ActionAddScalar (RunSection module) 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_ActionAddScalar 10 | #define MOD_RunSection_ActionAddScalar 11 | 12 | #include "Action.h" 13 | 14 | namespace RunSection 15 | { 16 | class ActionAddScalar : public Action 17 | { 18 | private: 19 | // Data members 20 | ActionScalar *actionScalar; 21 | 22 | protected: 23 | // Overwritten protected methods 24 | bool DoStep() override; 25 | bool DoValidate() override; 26 | bool Reset() override; 27 | 28 | public: 29 | // Constructors / Destructors 30 | ActionAddScalar(const MSDParser::ObjectParser &, const std::map &, const std::map &); // Normal constructor 31 | ~ActionAddScalar(); 32 | }; 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /RunSection/Actions/ActionScaleVector.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ActionScaleVector (RunSection module) 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_ActionScaleVector 10 | #define MOD_RunSection_ActionScaleVector 11 | 12 | #include "Action.h" 13 | 14 | namespace RunSection 15 | { 16 | class ActionScaleVector : public Action 17 | { 18 | private: 19 | // Data members 20 | ActionVector *actionVector; 21 | 22 | protected: 23 | // Overwritten protected methods 24 | bool DoStep() override; 25 | bool DoValidate() override; 26 | bool Reset() override; 27 | 28 | public: 29 | // Constructors / Destructors 30 | ActionScaleVector(const MSDParser::ObjectParser &, const std::map &, const std::map &); // Normal constructor 31 | ~ActionScaleVector(); 32 | }; 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /RunSection/Actions/ActionMultiplyScalar.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ActionMultiplyScalar (RunSection module) 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_ActionMultiplyScalar 10 | #define MOD_RunSection_ActionMultiplyScalar 11 | 12 | #include "Action.h" 13 | 14 | namespace RunSection 15 | { 16 | class ActionMultiplyScalar : public Action 17 | { 18 | private: 19 | // Data members 20 | ActionScalar *actionScalar; 21 | 22 | protected: 23 | // Overwritten protected methods 24 | bool DoStep() override; 25 | bool DoValidate() override; 26 | bool Reset() override; 27 | 28 | public: 29 | // Constructors / Destructors 30 | ActionMultiplyScalar(const MSDParser::ObjectParser &, const std::map &, const std::map &); // Normal constructor 31 | ~ActionMultiplyScalar(); 32 | }; 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSSPump.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticSSPump (RunSection module) 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskStaticSSPump 10 | #define MOD_RunSection_TaskStaticSSPump 11 | 12 | #include "BasicTask.h" 13 | #include "SpinAPIDefines.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskStaticSSPump : public BasicTask 18 | { 19 | private: 20 | double timestep; 21 | double totaltime; 22 | SpinAPI::ReactionOperatorType reactionOperators; 23 | 24 | void WriteHeader(std::ostream &); // Write header for the output file 25 | 26 | protected: 27 | bool RunLocal() override; 28 | bool Validate() override; 29 | 30 | public: 31 | // Constructors / Destructors 32 | TaskStaticSSPump(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 33 | ~TaskStaticSSPump(); // Destructor 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticHSSymmetricDecay.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticHSSymmetricDecay (RunSection module) 3 | // ------------------ 4 | // Hilbert space method. Assummes symmetric (spin independent) recombination. 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // (c) 2025 Quantum Biology and Computational Physics Group. 8 | // See LICENSE.txt for license information. 9 | ///////////////////////////////////////////////////////////////////////// 10 | #ifndef MOD_RunSection_TaskStaticHSSymmetricDecay 11 | #define MOD_RunSection_TaskStaticHSSymmetricDecay 12 | 13 | #include "BasicTask.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskStaticHSSymmetricDecay : public BasicTask 18 | { 19 | private: 20 | void WriteHeader(std::ostream &); // Write header for the output file 21 | 22 | protected: 23 | bool RunLocal() override; 24 | bool Validate() override; 25 | 26 | public: 27 | // Constructors / Destructors 28 | TaskStaticHSSymmetricDecay(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 29 | ~TaskStaticHSSymmetricDecay(); // Destructor 30 | }; 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSSTimeEvo.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticSSTimeEvo (RunSection module) 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskStaticSSTimeEvo 10 | #define MOD_RunSection_TaskStaticSSTimeEvo 11 | 12 | #include "BasicTask.h" 13 | #include "SpinAPIDefines.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskStaticSSTimeEvo : public BasicTask 18 | { 19 | private: 20 | double timestep; 21 | double totaltime; 22 | SpinAPI::ReactionOperatorType reactionOperators; 23 | 24 | void WriteHeader(std::ostream &); // Write header for the output file 25 | 26 | protected: 27 | bool RunLocal() override; 28 | bool Validate() override; 29 | 30 | public: 31 | // Constructors / Destructors 32 | TaskStaticSSTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 33 | ~TaskStaticSSTimeEvo(); // Destructor 34 | }; 35 | } 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /RunSection/Actions/ActionAddVector.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ActionAddVector (RunSection module) 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_ActionAddVector 10 | #define MOD_RunSection_ActionAddVector 11 | 12 | #include "Action.h" 13 | 14 | namespace RunSection 15 | { 16 | class ActionAddVector : public Action 17 | { 18 | private: 19 | // Data members 20 | ActionVector *actionVector; 21 | arma::vec direction; 22 | 23 | // Private methods 24 | bool SetDirection(const arma::vec &); 25 | 26 | protected: 27 | // Overwritten protected methods 28 | bool DoStep() override; 29 | bool DoValidate() override; 30 | bool Reset() override; 31 | 32 | public: 33 | // Constructors / Destructors 34 | ActionAddVector(const MSDParser::ObjectParser &, const std::map &, const std::map &); // Normal constructor 35 | ~ActionAddVector(); 36 | }; 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskPeriodicSSTimeEvo.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskPeriodicSSTimeEvo (RunSection module) 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskPeriodicSSTimeEvo 10 | #define MOD_RunSection_TaskPeriodicSSTimeEvo 11 | 12 | #include "BasicTask.h" 13 | #include "SpinAPIDefines.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskPeriodicSSTimeEvo : public BasicTask 18 | { 19 | private: 20 | double timestep; 21 | double totaltime; 22 | SpinAPI::ReactionOperatorType reactionOperators; 23 | unsigned int stepsPerPeriod; 24 | 25 | void WriteHeader(std::ostream &); // Write header for the output file 26 | 27 | protected: 28 | bool RunLocal() override; 29 | bool Validate() override; 30 | 31 | public: 32 | // Constructors / Destructors 33 | TaskPeriodicSSTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 34 | ~TaskPeriodicSSTimeEvo(); // Destructor 35 | }; 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticRPOnlyHSSymDec.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticHSSymmetricDecay (RunSection module) 3 | // ------------------ 4 | // Hilbert space method. Assummes symmetric (spin independent) recombination. 5 | // Note: Also assumes that we have a radical pair with non-interacting spins! 6 | // 7 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 8 | // (c) 2025 Quantum Biology and Computational Physics Group. 9 | // See LICENSE.txt for license information. 10 | ///////////////////////////////////////////////////////////////////////// 11 | #ifndef MOD_RunSection_TaskStaticRPOnlyHSSymDec 12 | #define MOD_RunSection_TaskStaticRPOnlyHSSymDec 13 | 14 | #include "BasicTask.h" 15 | 16 | namespace RunSection 17 | { 18 | class TaskStaticRPOnlyHSSymDec : public BasicTask 19 | { 20 | private: 21 | void WriteHeader(std::ostream &); // Write header for the output file 22 | 23 | protected: 24 | bool RunLocal() override; 25 | bool Validate() override; 26 | 27 | public: 28 | // Constructors / Destructors 29 | TaskStaticRPOnlyHSSymDec(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 30 | ~TaskStaticRPOnlyHSSymDec(); // Destructor 31 | }; 32 | } 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticHSDirectSpectra.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticHSDirectSpectra (RunSection module) by Luca Gerhards 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskStaticHSDirectSpectra 10 | #define MOD_RunSection_TaskStaticHSDirectSpectra 11 | 12 | #include "BasicTask.h" 13 | #include "SpinAPIDefines.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskStaticHSDirectSpectra : public BasicTask 18 | { 19 | private: 20 | 21 | double timestep; 22 | double totaltime; 23 | 24 | SpinAPI::ReactionOperatorType reactionOperators; 25 | 26 | void WriteHeader(std::ostream &); // Write header for the output file 27 | 28 | protected: 29 | bool RunLocal() override; 30 | bool Validate() override; 31 | 32 | public: 33 | // Constructors / Destructors 34 | TaskStaticHSDirectSpectra(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 35 | ~TaskStaticHSDirectSpectra(); // Destructor 36 | }; 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskGammaCompute.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskGammaCompute (RunSection module) 3 | // ------------------ 4 | // An implementation of the Gamma-COMPUTE algorithm for calculating RF 5 | // magnetic field effects with phase averaging. 6 | // 7 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 8 | // (c) 2025 Quantum Biology and Computational Physics Group. 9 | // See LICENSE.txt for license information. 10 | ///////////////////////////////////////////////////////////////////////// 11 | #ifndef MOD_RunSection_TaskGammaCompute 12 | #define MOD_RunSection_TaskGammaCompute 13 | 14 | #include "SpinSpace.h" 15 | #include "BasicTask.h" 16 | 17 | namespace RunSection 18 | { 19 | class TaskGammaCompute : public BasicTask 20 | { 21 | private: 22 | unsigned int steps; 23 | double totaltime; 24 | 25 | // Private methods 26 | void WriteHeader(std::ostream &); // Write header for the output file 27 | 28 | protected: 29 | bool RunLocal() override; 30 | bool Validate() override; 31 | 32 | public: 33 | // Constructors / Destructors 34 | TaskGammaCompute(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 35 | ~TaskGammaCompute(); // Destructor 36 | }; 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /RunSection/Actions/ActionRotateVector.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ActionRotateVector (RunSection module) 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_ActionRotateVector 10 | #define MOD_RunSection_ActionRotateVector 11 | 12 | #include "Action.h" 13 | 14 | namespace RunSection 15 | { 16 | class ActionRotateVector : public Action 17 | { 18 | private: 19 | // Data members 20 | ActionVector *actionVector; 21 | arma::vec axis; 22 | arma::vec refAxis1; 23 | arma::vec refAxis2; 24 | 25 | // Private methods 26 | bool SetAxis(const arma::vec &); 27 | 28 | protected: 29 | // Overwritten protected methods 30 | bool DoStep() override; 31 | bool DoValidate() override; 32 | bool Reset() override; 33 | 34 | public: 35 | // Constructors / Destructors 36 | ActionRotateVector(const MSDParser::ObjectParser &, const std::map &, const std::map &); // Normal constructor 37 | ~ActionRotateVector(); 38 | }; 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSSRelaxation.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticSSRelaxation (RunSection module) 3 | // ------------------ 4 | // 5 | // Simple quantum yield calculation in Liouville space, derived from the 6 | // properties of the Laplace transformation. 7 | // 8 | // (c) 2018 by Claus N. 9 | ///////////////////////////////////////////////////////////////////////// 10 | #ifndef MOD_RunSection_TaskStaticSSRelaxation 11 | #define MOD_RunSection_TaskStaticSSRelaxation 12 | 13 | #include "BasicTask.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskStaticSSRelaxation : public BasicTask 18 | { 19 | private: 20 | double relaxationRate; 21 | std::vector relaxingSpins; 22 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 23 | // If false, a quantum yield will be calculated each defined State object 24 | 25 | void WriteHeader(std::ostream &); // Write header for the output file 26 | 27 | protected: 28 | bool RunLocal() override; 29 | bool Validate() override; 30 | 31 | public: 32 | // Constructors / Destructors 33 | TaskStaticSSRelaxation(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 34 | ~TaskStaticSSRelaxation(); // Destructor 35 | }; 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /RunSection/RunSectionDefines.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // RunSection Defines (RunSection Module) 3 | // ------------------ 4 | // Definitions used by the RunSection Module. 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // (c) 2025 Quantum Biology and Computational Physics Group. 8 | // See LICENSE.txt for license information. 9 | ///////////////////////////////////////////////////////////////////////// 10 | #ifndef MOD_RunSection_Defines 11 | #define MOD_RunSection_Defines 12 | 13 | namespace RunSection 14 | { 15 | // Message type used by the OutputHandler class 16 | using MessageType = unsigned int; 17 | 18 | // A bitmask with all bits for normal message categories set to 1 19 | const MessageType NormalMessage = 7; 20 | 21 | // Normal message categories 22 | const MessageType MessageType_Details = 1; 23 | const MessageType MessageType_Normal = 2; 24 | const MessageType MessageType_Important = 3; 25 | const MessageType MessageType_Critical = 4; 26 | 27 | // Special message categories 28 | const MessageType MessageType_Warning = 8; 29 | const MessageType MessageType_Error = 16; 30 | 31 | // The notification level that is used if nothing else is specified 32 | const MessageType DefaultNotificationLevel = MessageType_Normal | MessageType_Warning | MessageType_Error; 33 | } 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskActionSpectrumHistogram.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskActionSpectrumHistogram (RunSection module) 3 | // ------------------ 4 | // Computes the action-spectrum histogram of a spin system, see Hiscock et al. (2017) and Leberecht et al. (2022). 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // Task implemented by Siu Ying Wong and Luca Gerhards 8 | // (c) 2022 Quantum Biology and Computational Physics Group. 9 | // See LICENSE.txt for license information. 10 | ///////////////////////////////////////////////////////////////////////// 11 | #ifndef MOD_RunSection_TaskActionSpectrumHistogram 12 | #define MOD_RunSection_TaskActionSpectrumHistogram 13 | 14 | #include "SpinSpace.h" 15 | #include "BasicTask.h" 16 | 17 | namespace RunSection 18 | { 19 | class TaskActionSpectrumHistogram : public BasicTask 20 | { 21 | private: 22 | // Data members 23 | 24 | // Private methods 25 | arma::vec GetHistogramBinCenters(); 26 | void WriteHeader(std::ostream &); // Write header for the output file 27 | 28 | protected: 29 | bool RunLocal() override; 30 | bool Validate() override; 31 | 32 | public: 33 | // Constructors / Destructors 34 | TaskActionSpectrumHistogram(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 35 | ~TaskActionSpectrumHistogram(); // Destructor 36 | }; 37 | } 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSS.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticSS (RunSection module) 3 | // ------------------ 4 | // 5 | // Simple quantum yield calculation in Liouville space, derived from the 6 | // properties of the Laplace transformation. 7 | // 8 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 9 | // (c) 2025 Quantum Biology and Computational Physics Group. 10 | // See LICENSE.txt for license information. 11 | ///////////////////////////////////////////////////////////////////////// 12 | #ifndef MOD_RunSection_TaskStaticSS 13 | #define MOD_RunSection_TaskStaticSS 14 | 15 | #include "BasicTask.h" 16 | #include "SpinAPIDefines.h" 17 | 18 | namespace RunSection 19 | { 20 | class TaskStaticSS : public BasicTask 21 | { 22 | private: 23 | SpinAPI::ReactionOperatorType reactionOperators; 24 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 25 | // If false, a quantum yield will be calculated each defined State object 26 | 27 | void WriteHeader(std::ostream &); // Write header for the output file 28 | 29 | protected: 30 | bool RunLocal() override; 31 | bool Validate() override; 32 | 33 | public: 34 | // Constructors / Destructors 35 | TaskStaticSS(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 36 | ~TaskStaticSS(); // Destructor 37 | }; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSSCIDNP.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticSSCIDNP (RunSection module) 3 | // ------------------ 4 | // 5 | // Simple quantum yield calculation in Liouville space, derived from the 6 | // properties of the Laplace transformation. 7 | // 8 | // Molecular Spin Dynamics Software - developed by Luca Gerhards. 9 | // (c) 2022 Quantum Biology and Computational Physics Group. 10 | // See LICENSE.txt for license information. 11 | ///////////////////////////////////////////////////////////////////////// 12 | #ifndef MOD_RunSection_TaskStaticSSCIDNP 13 | #define MOD_RunSection_TaskStaticSSCIDNP 14 | 15 | #include "BasicTask.h" 16 | #include "SpinAPIDefines.h" 17 | 18 | namespace RunSection 19 | { 20 | class TaskStaticSSCIDNP : public BasicTask 21 | { 22 | private: 23 | SpinAPI::ReactionOperatorType reactionOperators; 24 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 25 | // If false, a quantum yield will be calculated each defined State object 26 | 27 | void WriteHeader(std::ostream &); // Write header for the output file 28 | 29 | protected: 30 | bool RunLocal() override; 31 | bool Validate() override; 32 | 33 | public: 34 | // Constructors / Destructors 35 | TaskStaticSSCIDNP(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 36 | ~TaskStaticSSCIDNP(); // Destructor 37 | }; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskMultiStaticSS.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskMultiStaticSS(RunSection module) 3 | // ------------------ 4 | // 5 | // Simple time-evolution calculation in Liouville space. 6 | // 7 | // -- Multi-system version: Allows transitions between SpinSystems -- 8 | // -- When applicable uses a Tridagonal Block Solver instead of the Armadillo solver -- 9 | // 10 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 11 | // (c) 2025 Quantum Biology and Computational Physics Group. 12 | // See LICENSE.txt for license information. 13 | ///////////////////////////////////////////////////////////////////////// 14 | #ifndef MOD_RunSection_TaskMultiStaticSS 15 | #define MOD_RunSection_TaskMultiStaticSS 16 | 17 | #include "BasicTask.h" 18 | #include "SpinSpace.h" 19 | #include "SpinSystem.h" 20 | #include "SpinAPIDefines.h" 21 | 22 | namespace RunSection 23 | { 24 | class TaskMultiStaticSS : public BasicTask 25 | { 26 | private: 27 | double timestep; 28 | double totaltime; 29 | bool productYieldsOnly; 30 | SpinAPI::ReactionOperatorType reactionOperators; 31 | 32 | void WriteHeader(std::ostream &); // Write header for the output file 33 | 34 | protected: 35 | bool RunLocal() override; 36 | bool Validate() override; 37 | 38 | public: 39 | // Constructors / Destructors 40 | TaskMultiStaticSS(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 41 | ~TaskMultiStaticSS(); // Destructor 42 | }; 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /RunSection/Actions/ActionFibonacciSphere.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ActionFibonacciSphere (RunSection module) 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_ActionFibonacciSphere 10 | #define MOD_RunSection_ActionFibonacciSphere 11 | 12 | #include "Action.h" 13 | 14 | #include 15 | #include 16 | 17 | namespace RunSection 18 | { 19 | class ActionFibonacciSphere : public Action 20 | { 21 | private: 22 | // Data members 23 | ActionVector *actionVector; 24 | 25 | // std::vector> points; //stores y and theta 26 | typedef std::pair point; 27 | point *m_Points; // stores y and theta 28 | int m_Num; 29 | int m_Step; 30 | double m_Magnitude; // Maginitude of the intial vector; 31 | 32 | private: 33 | bool CalculatePoints(int n); 34 | bool GetPoint(std::array &); 35 | 36 | protected: 37 | // Overwritten protected methods 38 | bool DoStep() override; 39 | bool DoValidate() override; 40 | bool Reset() override; 41 | 42 | public: 43 | // Constructors / Destructors 44 | ActionFibonacciSphere(const MSDParser::ObjectParser &, const std::map &, const std::map &); // Normal constructor 45 | ~ActionFibonacciSphere(); 46 | }; 47 | 48 | } 49 | 50 | #endif -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticHSStochYieldsSymmUncoupled.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticHSStochYieldsSymmUncoupled (RunSection module) by Gediminas Pazera and Luca Gerhards 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskStaticHSStochYieldsSymmUncoupled 10 | #define MOD_RunSection_TaskStaticHSStochYieldsSymmUncoupled 11 | 12 | #include "BasicTask.h" 13 | #include "SpinAPIDefines.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskStaticHSStochYieldsSymmUncoupled : public BasicTask 18 | { 19 | private: 20 | 21 | double timestep; 22 | double totaltime; 23 | 24 | SpinAPI::ReactionOperatorType reactionOperators; 25 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 26 | // If false, a quantum yield will be calculated each defined State object 27 | void WriteHeader(std::ostream &); // Write header for the output file 28 | 29 | protected: 30 | bool RunLocal() override; 31 | bool Validate() override; 32 | 33 | public: 34 | // Constructors / Destructors 35 | TaskStaticHSStochYieldsSymmUncoupled(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 36 | ~TaskStaticHSStochYieldsSymmUncoupled(); // Destructor 37 | }; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticHSDirectYieldsSymmUncoupled.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticHSDirectYieldsSymmUncoupled (RunSection module) by Gediminas Pazera and Luca Gerhards 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskStaticHSDirectYieldsSymmUncoupled 10 | #define MOD_RunSection_TaskStaticHSDirectYieldsSymmUncoupled 11 | 12 | #include "BasicTask.h" 13 | #include "SpinAPIDefines.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskStaticHSDirectYieldsSymmUncoupled : public BasicTask 18 | { 19 | private: 20 | 21 | double timestep; 22 | double totaltime; 23 | 24 | SpinAPI::ReactionOperatorType reactionOperators; 25 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 26 | // If false, a quantum yield will be calculated each defined State object 27 | void WriteHeader(std::ostream &); // Write header for the output file 28 | 29 | protected: 30 | bool RunLocal() override; 31 | bool Validate() override; 32 | 33 | public: 34 | // Constructors / Destructors 35 | TaskStaticHSDirectYieldsSymmUncoupled(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 36 | ~TaskStaticHSDirectYieldsSymmUncoupled(); // Destructor 37 | }; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticHSStochTimeEvoSymmUncoupled.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticHSStochTimeEvoSymmUncoupled (RunSection module) by Gediminas Pazera and Luca Gerhards 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskStaticHSStochTimeEvoSymmUncoupled 10 | #define MOD_RunSection_TaskStaticHSStochTimeEvoSymmUncoupled 11 | 12 | #include "BasicTask.h" 13 | #include "SpinAPIDefines.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskStaticHSStochTimeEvoSymmUncoupled : public BasicTask 18 | { 19 | private: 20 | 21 | double timestep; 22 | double totaltime; 23 | 24 | SpinAPI::ReactionOperatorType reactionOperators; 25 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 26 | // If false, a quantum yield will be calculated each defined State object 27 | void WriteHeader(std::ostream &); // Write header for the output file 28 | 29 | protected: 30 | bool RunLocal() override; 31 | bool Validate() override; 32 | 33 | public: 34 | // Constructors / Destructors 35 | TaskStaticHSStochTimeEvoSymmUncoupled(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 36 | ~TaskStaticHSStochTimeEvoSymmUncoupled(); // Destructor 37 | }; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /RunSection/Actions/ActionLogSpace.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ActionLogSpace (RunSection module) 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_ActionLogSpace 10 | #define MOD_RunSection_ActionLogSpace 11 | 12 | #include "Action.h" 13 | #include 14 | #include 15 | namespace RunSection 16 | { 17 | class ActionLogSpace : public Action 18 | { 19 | private: 20 | // Data members 21 | ActionScalar *actionScaler; 22 | arma::rowvec m_Points; 23 | int m_Num; // number of points 24 | int m_Step; 25 | std::pair m_Bounds; // upper and lower bounds for the log space 26 | private: 27 | bool CalculatePoints(int, double, double); // generates a list of numbers between log base 10 num1 and log base 10 num2 28 | bool GetPoint(double &); // gets the current value and assignes it to the double& variable 29 | protected: 30 | // overwritten protected methods 31 | bool DoStep() override; 32 | bool DoValidate() override; 33 | bool Reset() override; 34 | 35 | public: 36 | ActionLogSpace(const MSDParser::ObjectParser &, const std::map &, const std::map &); // Normal constructor 37 | }; 38 | } 39 | 40 | #endif -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticHSDirectTimeEvoSymmUncoupled.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticHSDirectTimeEvoSymmUncoupled (RunSection module) by Gediminas Pazera and Luca Gerhards 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskStaticHSDirectTimeEvoSymmUncoupled 10 | #define MOD_RunSection_TaskStaticHSDirectTimeEvoSymmUncoupled 11 | 12 | #include "BasicTask.h" 13 | #include "SpinAPIDefines.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskStaticHSDirectTimeEvoSymmUncoupled : public BasicTask 18 | { 19 | private: 20 | 21 | double timestep; 22 | double totaltime; 23 | 24 | SpinAPI::ReactionOperatorType reactionOperators; 25 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 26 | // If false, a quantum yield will be calculated each defined State object 27 | void WriteHeader(std::ostream &); // Write header for the output file 28 | 29 | protected: 30 | bool RunLocal() override; 31 | bool Validate() override; 32 | 33 | public: 34 | // Constructors / Destructors 35 | TaskStaticHSDirectTimeEvoSymmUncoupled(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 36 | ~TaskStaticHSDirectTimeEvoSymmUncoupled(); // Destructor 37 | }; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticHSDirectYields.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticHSDirectYields (RunSection module) by Gediminas Pazera and Luca Gerhards 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskStaticHSDirectYields 10 | #define MOD_RunSection_TaskStaticHSDirectYields 11 | 12 | #include "BasicTask.h" 13 | #include "SpinAPIDefines.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskStaticHSDirectYields : public BasicTask 18 | { 19 | private: 20 | 21 | double timestep; 22 | double totaltime; 23 | 24 | SpinAPI::ReactionOperatorType reactionOperators; 25 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 26 | // If false, a quantum yield will be calculated each defined State object 27 | void WriteHeader(std::ostream &); // Write header for the output file 28 | 29 | protected: 30 | bool RunLocal() override; 31 | bool Validate() override; 32 | 33 | public: 34 | // Constructors / Destructors 35 | TaskStaticHSDirectYields(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 36 | ~TaskStaticHSDirectYields(); // Destructor 37 | bool is_identity_matrix(arma::sp_cx_mat &matrix); // check if the matrix is an identity 38 | }; 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticHSStochTimeEvo.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticHSStochTimeEvo (RunSection module) by Gediminas Pazera and Luca Gerhards 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskStaticHSStochTimeEvo 10 | #define MOD_RunSection_TaskStaticHSStochTimeEvo 11 | 12 | #include "BasicTask.h" 13 | #include "SpinAPIDefines.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskStaticHSStochTimeEvo : public BasicTask 18 | { 19 | private: 20 | 21 | double timestep; 22 | double totaltime; 23 | 24 | SpinAPI::ReactionOperatorType reactionOperators; 25 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 26 | // If false, a quantum yield will be calculated each defined State object 27 | void WriteHeader(std::ostream &); // Write header for the output file 28 | 29 | protected: 30 | bool RunLocal() override; 31 | bool Validate() override; 32 | 33 | public: 34 | // Constructors / Destructors 35 | TaskStaticHSStochTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 36 | ~TaskStaticHSStochTimeEvo(); // Destructor 37 | bool is_identity_matrix(arma::sp_cx_mat &matrix); // check if the matrix is an identity 38 | }; 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticHSDirectTimeEvo.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticHSDirectTimeEvo (RunSection module) by Gediminas Pazera and Luca Gerhards 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskStaticHSDirectTimeEvo 10 | #define MOD_RunSection_TaskStaticHSDirectTimeEvo 11 | 12 | #include "BasicTask.h" 13 | #include "SpinAPIDefines.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskStaticHSDirectTimeEvo : public BasicTask 18 | { 19 | private: 20 | 21 | double timestep; 22 | double totaltime; 23 | 24 | SpinAPI::ReactionOperatorType reactionOperators; 25 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 26 | // If false, a quantum yield will be calculated each defined State object 27 | void WriteHeader(std::ostream &); // Write header for the output file 28 | 29 | protected: 30 | bool RunLocal() override; 31 | bool Validate() override; 32 | 33 | public: 34 | // Constructors / Destructors 35 | TaskStaticHSDirectTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 36 | ~TaskStaticHSDirectTimeEvo(); // Destructor 37 | bool is_identity_matrix(arma::sp_cx_mat &matrix); // check if the matrix is an identity 38 | }; 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskMultiStaticSSTimeEvoSpectra.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskMultiStaticSSTimeEvoSpectra (RunSection module) 3 | // ------------------ 4 | // 5 | // Simple time-evolution calculation in Liouville space. 6 | // 7 | // -- Multi-system version: Allows transitions between SpinSystems -- 8 | // 9 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 10 | // (c) 2025 Quantum Biology and Computational Physics Group. 11 | // See LICENSE.txt for license information. 12 | ///////////////////////////////////////////////////////////////////////// 13 | #ifndef MOD_RunSection_TaskMultiStaticSSTimeEvoSpectra 14 | #define MOD_RunSection_TaskMultiStaticSSTimeEvoSpectra 15 | 16 | #include "BasicTask.h" 17 | #include "SpinSpace.h" 18 | #include "SpinSystem.h" 19 | #include "SpinAPIDefines.h" 20 | 21 | namespace RunSection 22 | { 23 | class TaskMultiStaticSSTimeEvoSpectra : public BasicTask 24 | { 25 | private: 26 | double timestep; 27 | double totaltime; 28 | bool productYieldsOnly; 29 | SpinAPI::ReactionOperatorType reactionOperators; 30 | 31 | void WriteHeader(std::ostream &); // Write header for the output file 32 | 33 | // Private method that gathers and outputs the results from a given time-integrated density operator 34 | bool GatherResults(const arma::cx_mat &, const SpinAPI::SpinSystem &, const SpinAPI::SpinSpace &); 35 | 36 | protected: 37 | bool RunLocal() override; 38 | bool Validate() override; 39 | 40 | public: 41 | // Constructors / Destructors 42 | TaskMultiStaticSSTimeEvoSpectra(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 43 | ~TaskMultiStaticSSTimeEvoSpectra(); // Destructor 44 | }; 45 | } 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /MSDParser/MSDParserDefines.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // Defines (MSDParser Module) 3 | // ------------------ 4 | // Definitions used by the MSDParser Module. 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // (c) 2025 Quantum Biology and Computational Physics Group. 8 | // See LICENSE.txt for license information. 9 | ///////////////////////////////////////////////////////////////////////// 10 | #ifndef MOD_MSDParser_Defines 11 | #define MOD_MSDParser_Defines 12 | 13 | namespace MSDParser 14 | { 15 | enum class ObjectGroup 16 | { 17 | SpinSystem, 18 | Settings, 19 | Run, 20 | None, // FileReader is not currently within an object group 21 | }; 22 | 23 | enum class ObjectType 24 | { 25 | Spin = 0, 26 | Interaction, 27 | Transition, 28 | Operator, 29 | State, 30 | Pulse, 31 | SubSystem, 32 | Output, 33 | Task, 34 | Action, 35 | Settings, 36 | Properties, 37 | Undefined, // Indicates that no valid object was read (e.g. nothing read yet, or a read object is of an unknown type) 38 | EOFObject, // Indicates that there are no more objects in the input file 39 | }; 40 | 41 | struct MSDFileObject 42 | { 43 | private: 44 | ObjectType type; 45 | std::string name; 46 | std::string contents; 47 | 48 | public: 49 | MSDFileObject(ObjectType _type = ObjectType::EOFObject, std::string _name = "", std::string _contents = "") : type(_type), name(_name), contents(_contents){}; 50 | MSDFileObject(const MSDFileObject &_obj) : type(_obj.type), name(_obj.name), contents(_obj.contents){}; 51 | 52 | ObjectType Type() const { return type; }; 53 | std::string Name() const { return name; }; 54 | std::string Contents() const { return contents; }; 55 | }; 56 | } 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskHamiltonianEigenvalues.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskHamiltonianEigenvalues (RunSection module) 3 | // ------------------ 4 | // Prints the eigenvalues, and eigenvectors & Hamiltonian if asked for it. 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // (c) 2025 Quantum Biology and Computational Physics Group. 8 | // See LICENSE.txt for license information. 9 | ///////////////////////////////////////////////////////////////////////// 10 | #ifndef MOD_RunSection_TaskHamiltonianEigenvalues 11 | #define MOD_RunSection_TaskHamiltonianEigenvalues 12 | 13 | #include "SpinSpace.h" 14 | #include "BasicTask.h" 15 | 16 | namespace RunSection 17 | { 18 | class TaskHamiltonianEigenvalues : public BasicTask 19 | { 20 | private: 21 | // Data members 22 | bool printEigenvectors; 23 | bool printHamiltonian; 24 | bool useSuperspace; 25 | bool separateRealImag; 26 | double initialTime; 27 | double totalTime; 28 | double timestep; 29 | bool resonanceFrequencies; 30 | std::vector referenceStates; 31 | std::vector transitionSpins; // Used for transition matrix element calculations 32 | 33 | // Private methods 34 | void WriteHeader(std::ostream &); // Write header for the output file 35 | void GetResonanceFrequencies(const arma::vec &, const arma::cx_mat &, const std::shared_ptr &, const SpinAPI::SpinSpace &); 36 | 37 | protected: 38 | bool RunLocal() override; 39 | bool Validate() override; 40 | 41 | public: 42 | // Constructors / Destructors 43 | TaskHamiltonianEigenvalues(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 44 | ~TaskHamiltonianEigenvalues(); // Destructor 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskDynamicHSDirectSpectra.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskDynamicHSDirectSpectra (RunSection module) by Luca Gerhards 3 | // ------------------ 4 | // 5 | // Very efficient quantum yield calculations in Hilbert Space, using Monte Carlo sampling. 6 | // For dynamic time-dependent Hamiltonians. 7 | // 8 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 9 | // (c) 2025 Quantum Biology and Computational Physics Group. 10 | // See LICENSE.txt for license information. 11 | ///////////////////////////////////////////////////////////////////////// 12 | #ifndef MOD_RunSection_TaskDynamicHSDirectSpectra 13 | #define MOD_RunSection_TaskDynamicHSDirectSpectra 14 | 15 | #include "BasicTask.h" 16 | #include "SpinAPIDefines.h" 17 | 18 | namespace RunSection 19 | { 20 | class TaskDynamicHSDirectSpectra : public BasicTask 21 | { 22 | private: 23 | // Things for time dependent Hamiltonian 24 | 25 | double timestep; 26 | double totaltime; 27 | bool timedependentInteractions; 28 | bool timedependentTransitions; 29 | 30 | // 31 | 32 | SpinAPI::ReactionOperatorType reactionOperators; 33 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 34 | // If false, a quantum yield will be calculated each defined State object 35 | void WriteHeader(std::ostream &); // Write header for the output file 36 | protected: 37 | bool RunLocal() override; 38 | bool Validate() override; 39 | 40 | public: 41 | // Constructors / Destructors 42 | TaskDynamicHSDirectSpectra(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 43 | ~TaskDynamicHSDirectSpectra(); // Destructor 44 | bool is_identity_matrix(arma::sp_cx_mat &matrix); // check if the matrix is an identity 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskDynamicHSStochYields.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskDynamicHSStochYields (RunSection module) by Gediminas Pazera and Luca Gerhards 3 | // ------------------ 4 | // 5 | // Very efficient quantum yield calculations in Hilbert Space, using Monte Carlo sampling. 6 | // For dynamic time-dependent Hamiltonians. 7 | // 8 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 9 | // (c) 2025 Quantum Biology and Computational Physics Group. 10 | // See LICENSE.txt for license information. 11 | ///////////////////////////////////////////////////////////////////////// 12 | #ifndef MOD_RunSection_TaskDynamicHSStochYields 13 | #define MOD_RunSection_TaskDynamicHSStochYields 14 | 15 | #include "BasicTask.h" 16 | #include "SpinAPIDefines.h" 17 | 18 | namespace RunSection 19 | { 20 | class TaskDynamicHSStochYields : public BasicTask 21 | { 22 | private: 23 | // Things for time dependent Hamiltonian 24 | double timestep; 25 | double totaltime; 26 | bool timedependentInteractions; 27 | bool timedependentTransitions; 28 | 29 | // 30 | 31 | SpinAPI::ReactionOperatorType reactionOperators; 32 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 33 | // If false, a quantum yield will be calculated each defined State object 34 | void WriteHeader(std::ostream &); // Write header for the output file 35 | 36 | protected: 37 | bool RunLocal() override; 38 | bool Validate() override; 39 | 40 | public: 41 | // Constructors / Destructors 42 | TaskDynamicHSStochYields(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 43 | ~TaskDynamicHSStochYields(); // Destructor 44 | bool is_identity_matrix(arma::sp_cx_mat &matrix); // check if the matrix is an identity 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskDynamicHSDirectYields.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskDynamicHSDirectYields (RunSection module) by Gediminas Pazera and Luca Gerhards 3 | // ------------------ 4 | // 5 | // Very efficient quantum yield calculations in Hilbert Space, using Monte Carlo sampling. 6 | // For dynamic time-dependent Hamiltonians. 7 | // 8 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 9 | // (c) 2025 Quantum Biology and Computational Physics Group. 10 | // See LICENSE.txt for license information. 11 | ///////////////////////////////////////////////////////////////////////// 12 | #ifndef MOD_RunSection_TaskDynamicHSDirectYields 13 | #define MOD_RunSection_TaskDynamicHSDirectYields 14 | 15 | #include "BasicTask.h" 16 | #include "SpinAPIDefines.h" 17 | 18 | namespace RunSection 19 | { 20 | class TaskDynamicHSDirectYields : public BasicTask 21 | { 22 | private: 23 | // Things for time dependent Hamiltonian 24 | 25 | double timestep; 26 | double totaltime; 27 | bool timedependentInteractions; 28 | bool timedependentTransitions; 29 | 30 | // 31 | 32 | SpinAPI::ReactionOperatorType reactionOperators; 33 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 34 | // If false, a quantum yield will be calculated each defined State object 35 | void WriteHeader(std::ostream &); // Write header for the output file 36 | protected: 37 | bool RunLocal() override; 38 | bool Validate() override; 39 | 40 | public: 41 | // Constructors / Destructors 42 | TaskDynamicHSDirectYields(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 43 | ~TaskDynamicHSDirectYields(); // Destructor 44 | bool is_identity_matrix(arma::sp_cx_mat &matrix); // check if the matrix is an identity 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskDynamicHSStochTimeEvo.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskDynamicHSStochTimeEvo (RunSection module) by Gediminas Pazera and Luca Gerhards 3 | // ------------------ 4 | // 5 | // Very efficient quantum yield calculations in Hilbert Space, using Monte Carlo sampling. 6 | // For dynamic time-dependent Hamiltonians. 7 | // 8 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 9 | // (c) 2025 Quantum Biology and Computational Physics Group. 10 | // See LICENSE.txt for license information. 11 | ///////////////////////////////////////////////////////////////////////// 12 | #ifndef MOD_RunSection_TaskDynamicHSStochTimeEvo 13 | #define MOD_RunSection_TaskDynamicHSStochTimeEvo 14 | 15 | #include "BasicTask.h" 16 | #include "SpinAPIDefines.h" 17 | 18 | namespace RunSection 19 | { 20 | class TaskDynamicHSStochTimeEvo : public BasicTask 21 | { 22 | private: 23 | // Things for time dependent Hamiltonian 24 | 25 | double timestep; 26 | double totaltime; 27 | bool timedependentInteractions; 28 | bool timedependentTransitions; 29 | 30 | // 31 | 32 | SpinAPI::ReactionOperatorType reactionOperators; 33 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 34 | // If false, a quantum yield will be calculated each defined State object 35 | void WriteHeader(std::ostream &); // Write header for the output file 36 | 37 | protected: 38 | bool RunLocal() override; 39 | bool Validate() override; 40 | 41 | public: 42 | // Constructors / Destructors 43 | TaskDynamicHSStochTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 44 | ~TaskDynamicHSStochTimeEvo(); // Destructor 45 | bool is_identity_matrix(arma::sp_cx_mat &matrix); // check if the matrix is an identity 46 | }; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSSNakajimaZwanzigTimeEvo.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // MolSpin - Nakajima Zwanzig Theory Time Evolution Task - developed by Luca Gerhards 3 | // 4 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 5 | // (c) 2025 Quantum Biology and Computational Physics Group. 6 | // See LICENSE.txt for license information. 7 | ////////////////////////////////////////////////////////////////////////////// 8 | #ifndef MOD_RunSection_TaskStaticSSNakajimaZwanzigTimeEvo 9 | #define MOD_RunSection_TaskStaticSSNakajimaZwanzigTimeEvo 10 | 11 | #include "BasicTask.h" 12 | #include "SpinAPIDefines.h" 13 | 14 | namespace RunSection 15 | { 16 | class TaskStaticSSNakajimaZwanzigTimeEvo : public BasicTask 17 | { 18 | private: 19 | double timestep; 20 | double totaltime; 21 | SpinAPI::ReactionOperatorType reactionOperators; 22 | 23 | void WriteHeader(std::ostream &); // Write header for the output file 24 | bool NakajimaZwanzigtensorTimeEvo(const arma::cx_mat &_op1, const arma::cx_mat &_op2, const arma::cx_mat &_specdens, arma::cx_mat &_NakajimaZwanzigtensor); // Contruction of NakajimaZwanzigtensor with operator basis 25 | bool ConstructSpecDensGeneralTimeEvo(const std::vector &_ampl_list, const std::vector &_tau_c_list, const arma::cx_mat &_omega, arma::cx_mat &_specdens); 26 | bool ConstructSpecDensSpecificTimeEvo(const std::complex &_ampl, const std::complex &_tau_c, const arma::cx_mat &_omega, arma::cx_mat &_specdens); 27 | 28 | protected: 29 | bool RunLocal() override; 30 | bool Validate() override; 31 | 32 | public: 33 | // Constructors / Destructors 34 | TaskStaticSSNakajimaZwanzigTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 35 | ~TaskStaticSSNakajimaZwanzigTimeEvo(); // Destructor 36 | }; 37 | } 38 | 39 | #endif -------------------------------------------------------------------------------- /MSDParser/MSDParser.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // MSDParser class (MSDParser Module) 3 | // ------------------ 4 | // Class used to parse MSD input files. 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // (c) 2025 Quantum Biology and Computational Physics Group. 8 | // See LICENSE.txt for license information. 9 | ///////////////////////////////////////////////////////////////////////// 10 | #ifndef MOD_MSDParser_MSDParser 11 | #define MOD_MSDParser_MSDParser 12 | 13 | #include 14 | #include 15 | #include "MSDParserDefines.h" 16 | #include "SpinAPIfwd.h" 17 | #include "ObjectParser.h" 18 | #include "RunSectionfwd.h" 19 | 20 | namespace MSDParser 21 | { 22 | class MSDParser 23 | { 24 | private: 25 | // Implementation 26 | bool isLoaded = false; 27 | std::string filename; 28 | std::vector> systems; 29 | std::vector runTasks; 30 | std::vector runActions; 31 | std::vector settingsObjects; 32 | std::vector runOutputs; 33 | 34 | public: 35 | // Constructors / Destructors 36 | explicit MSDParser(std::string); // Normal constructor 37 | MSDParser(const MSDParser &) = delete; // Copy-constructor 38 | ~MSDParser(); // Destructor 39 | 40 | // Operators 41 | MSDParser &operator=(const MSDParser &) = delete; // Copy-assignment 42 | 43 | // Public methods 44 | bool Load(); 45 | std::string Filename() const { return this->filename; }; 46 | void FillRunSection(RunSection::RunSection &); // Loads data into a RunSection object 47 | }; 48 | 49 | // Non-member non-friend functions 50 | bool FileExists(const MSDParser &); // Check whether the file passed to the MSDParser exists 51 | bool FileLoaded(const MSDParser &); // Check whether the file passed to the MSDParser has been loaded 52 | } 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskDynamicHSDirectTimeEvo.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskDynamicHSDirectTimeEvo (RunSection module) by Gediminas Pazera and Luca Gerhards 3 | // ------------------ 4 | // 5 | // Very efficient quantum yield calculations in Hilbert Space, using Monte Carlo sampling. 6 | // For dynamic time-dependent Hamiltonians. 7 | // 8 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 9 | // (c) 2025 Quantum Biology and Computational Physics Group. 10 | // See LICENSE.txt for license information. 11 | ///////////////////////////////////////////////////////////////////////// 12 | #ifndef MOD_RunSection_TaskDynamicHSDirectTimeEvo 13 | #define MOD_RunSection_TaskDynamicHSDirectTimeEvo 14 | 15 | #include "BasicTask.h" 16 | #include "SpinAPIDefines.h" 17 | 18 | namespace RunSection 19 | { 20 | class TaskDynamicHSDirectTimeEvo : public BasicTask 21 | { 22 | private: 23 | // Things for time dependent Hamiltonian 24 | double timestep; 25 | double totaltime; 26 | bool timedependentInteractions; 27 | bool timedependentTransitions; 28 | 29 | // 30 | 31 | SpinAPI::ReactionOperatorType reactionOperators; 32 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 33 | // If false, a quantum yield will be calculated each defined State object 34 | void WriteHeader(std::ostream &); // Write header for the output file 35 | 36 | protected: 37 | bool RunLocal() override; 38 | bool Validate() override; 39 | 40 | public: 41 | // Constructors / Destructors 42 | TaskDynamicHSDirectTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 43 | ~TaskDynamicHSDirectTimeEvo(); // Destructor 44 | bool is_identity_matrix(arma::sp_cx_mat &matrix); // check if the matrix is an identity 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskMultiStaticSSTimeEvo.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskMultiStaticSSTimeEvo (RunSection module) 3 | // ------------------ 4 | // 5 | // Simple time-evolution calculation in Liouville space. 6 | // 7 | // -- Multi-system version: Allows transitions between SpinSystems -- 8 | // 9 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 10 | // (c) 2025 Quantum Biology and Computational Physics Group. 11 | // See LICENSE.txt for license information. 12 | ///////////////////////////////////////////////////////////////////////// 13 | #ifndef MOD_RunSection_TaskMultiStaticSSTimeEvo 14 | #define MOD_RunSection_TaskMultiStaticSSTimeEvo 15 | 16 | #include "BasicTask.h" 17 | #include "SpinSpace.h" 18 | #include "SpinSystem.h" 19 | #include "SpinAPIDefines.h" 20 | 21 | namespace RunSection 22 | { 23 | class TaskMultiStaticSSTimeEvo : public BasicTask 24 | { 25 | private: 26 | double timestep; 27 | double totaltime; 28 | SpinAPI::ReactionOperatorType reactionOperators; 29 | 30 | void WriteHeader(std::ostream &); // Write header for the output file 31 | 32 | // Private method that gathers and outputs the results from a given time-integrated density operator 33 | void GatherResults(const arma::cx_mat &, const SpinAPI::SpinSystem &, const SpinAPI::SpinSpace &); 34 | bool SeperateSpinSystems(const arma::cx_vec& rho0, const std::vector>>& spaces); 35 | 36 | static arma::cx_vec ComputeRhoDot(double t, arma::sp_cx_mat& L, arma::cx_vec& K, arma::cx_vec RhoNaught); 37 | 38 | protected: 39 | bool RunLocal() override; 40 | bool Validate() override; 41 | 42 | public: 43 | // Constructors / Destructors 44 | TaskMultiStaticSSTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 45 | ~TaskMultiStaticSSTimeEvo(); // Destructor 46 | }; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /SpinAPI/Operator.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // Operator class (SpinAPI Module) 3 | // ------------------ 4 | // Special operators to be used in some task types. 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // (c) 2025 Quantum Biology and Computational Physics Group. 8 | // See LICENSE.txt for license information. 9 | ///////////////////////////////////////////////////////////////////////// 10 | #ifndef MOD_SpinAPI_Operator 11 | #define MOD_SpinAPI_Operator 12 | 13 | #include 14 | #include 15 | #include "SpinAPIDefines.h" 16 | #include "MSDParserfwd.h" 17 | #include "SpinAPIfwd.h" 18 | 19 | namespace SpinAPI 20 | { 21 | class Operator 22 | { 23 | private: 24 | // Implementation details 25 | std::shared_ptr properties; 26 | OperatorType type; 27 | std::vector spins; 28 | double rate1; 29 | double rate2; 30 | double rate3; 31 | bool isValid; 32 | 33 | public: 34 | // Constructors / Destructors 35 | Operator(std::string, std::string); // Normal constructor 36 | Operator(const Operator &); // Copy-constructor 37 | ~Operator(); // Destructor 38 | 39 | // Operators 40 | const Operator &operator=(const Operator &); // Copy-assignment 41 | 42 | // Name and validation 43 | std::string Name() const; 44 | bool Validate(const std::vector> &); 45 | bool IsValid() const; 46 | 47 | // Public property methods 48 | OperatorType Type() const; 49 | std::vector Spins() const; 50 | unsigned int SpinCount() const; 51 | double Rate1() const; 52 | double Rate2() const; 53 | double Rate3() const; 54 | 55 | // Allow access to custom properties to be used for custom tasks 56 | std::shared_ptr Properties() const; 57 | }; 58 | 59 | // Define alias for Operator-pointers 60 | using operator_ptr = std::shared_ptr; 61 | 62 | // Non-member non-friend functions 63 | bool IsValid(const Operator &); 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSSNakajimaZwanzig.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // MolSpin - Nakajima Zwanzig Theory Task - developed by Luca Gerhards 3 | // 4 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 5 | // (c) 2025 Quantum Biology and Computational Physics Group. 6 | // See LICENSE.txt for license information. 7 | ////////////////////////////////////////////////////////////////////////////// 8 | #ifndef MOD_RunSection_TaskStaticSSNakajimaZwanzig 9 | #define MOD_RunSection_TaskStaticSSNakajimaZwanzig 10 | 11 | #include "BasicTask.h" 12 | #include "SpinAPIDefines.h" 13 | 14 | namespace RunSection 15 | { 16 | class TaskStaticSSNakajimaZwanzig : public BasicTask 17 | { 18 | private: 19 | SpinAPI::ReactionOperatorType reactionOperators; 20 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 21 | // If false, a quantum yield will be calculated each defined State object 22 | void WriteHeader(std::ostream &); // Write header for the output file 23 | bool NakajimaZwanzigtensor(const arma::cx_mat &_op1, const arma::cx_mat &_op2, const arma::cx_mat &_specdens, arma::cx_mat &_NakajimaZwanzigtensor); // Contruction of NakajimaZwanzigtensor with operator basis 24 | bool ConstructSpecDensGeneral(const std::vector &_ampl_list, const std::vector &_tau_c_list, const arma::cx_mat &_omega, arma::cx_mat &_specdens); 25 | bool ConstructSpecDensSpecific(const std::complex &_ampl, const std::complex &_tau_c, const arma::cx_mat &_omega, arma::cx_mat &_specdens); 26 | 27 | protected: 28 | bool RunLocal() override; 29 | bool Validate() override; 30 | 31 | public: 32 | // Constructors / Destructors 33 | TaskStaticSSNakajimaZwanzig(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 34 | ~TaskStaticSSNakajimaZwanzig(); // Destructor 35 | }; 36 | } 37 | 38 | #endif -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSSRedfieldTimeEvo.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // MolSpin - Redfield Theory Task - developed by Luca Gerhards 3 | // 4 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 5 | // (c) 2025 Quantum Biology and Computational Physics Group. 6 | // See LICENSE.txt for license information. 7 | ////////////////////////////////////////////////////////////////////////////// 8 | #ifndef MOD_RunSection_TaskStaticSSRedfieldTimeEvo 9 | #define MOD_RunSection_TaskStaticSSRedfieldTimeEvo 10 | 11 | #include "BasicTask.h" 12 | #include "SpinAPIDefines.h" 13 | 14 | namespace RunSection 15 | { 16 | class TaskStaticSSRedfieldTimeEvo : public BasicTask 17 | { 18 | private: 19 | double timestep; 20 | double totaltime; 21 | SpinAPI::ReactionOperatorType reactionOperators; 22 | 23 | void WriteHeader(std::ostream &); // Write header for the output file 24 | bool RedfieldtensorTimeEvo(const arma::cx_mat &_op1, const arma::cx_mat &_op2, const arma::cx_mat &_specdens, arma::cx_mat &_redfieldtensor); // Contruction of Redfieldtensor with operator basis 25 | bool ConstructSpecDensGeneralTimeEvo(const int &_spectral_function, const std::vector &_ampl_list, const std::vector &_tau_c_list, const arma::cx_mat &_domega, arma::cx_mat &_specdens); 26 | bool ConstructSpecDensSpecificTimeEvo(const int &_spectral_function, const std::complex &_ampl, const std::complex &_tau_c, const arma::cx_mat &_domega, arma::cx_mat &_specdens); 27 | bool Slippage(arma::cx_mat **_ptr_Tensors, const int &_num_op, const arma::cx_mat &_eig_val_mat, const arma::cx_mat &_domega, const arma::cx_mat &_rho0, const std::complex &_tau_c, arma::cx_mat &_rho0_new); 28 | 29 | protected: 30 | bool RunLocal() override; 31 | bool Validate() override; 32 | 33 | public: 34 | // Constructors / Destructors 35 | TaskStaticSSRedfieldTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 36 | ~TaskStaticSSRedfieldTimeEvo(); // Destructor 37 | }; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskActionSpectrumHistogramRPOnlyDec.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskActionSpectrumHistogram (RunSection module) 3 | // ------------------ 4 | // Computes the action-spectrum histogram of an uncoupled radical pair, see Hiscock et al. (2017) and Leberecht et al. (2022). 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // Task implemented by Siu Ying Wong and Luca Gerhards. 8 | // (c) 2022 Quantum Biology and Computational Physics Group. 9 | // See LICENSE.txt for license information. 10 | ///////////////////////////////////////////////////////////////////////// 11 | #ifndef MOD_RunSection_TaskActionSpectrumHistogramRPOnlyDec 12 | #define MOD_RunSection_TaskActionSpectrumHistogramRPOnlyDec 13 | 14 | #include "SpinSpace.h" 15 | #include "BasicTask.h" 16 | 17 | namespace RunSection 18 | { 19 | class TaskActionSpectrumHistogramRPOnlyDec : public BasicTask 20 | { 21 | private: 22 | // Data members 23 | 24 | // Private methods 25 | long long GetNumDifferencesRPOnlyDec(long long dimension); 26 | arma::vec GetDifferencesRPOnlyDec(arma::vec values); 27 | arma::cx_vec GetPopulationVector(const int &Z1, const int &Z2, const arma::cx_mat &V1, const arma::cx_mat &V2); 28 | arma::vec GetPerpendicular3DVectorRPOnlyDec(arma::vec vector, bool normalise); 29 | arma::vec GetResonanceEffectsRPOnlyDec(arma::cx_vec initialstatepopulation, arma::sp_cx_mat transitionhamiltonian); 30 | double GetHistogramPrefactorRPOnlyDec(bool useMHzunits); 31 | arma::vec GetNormalisedHistogramHeightsRPOnlyDec(arma::vec energygaps, arma::vec resonanceeffects, double binwidth, int numbins, bool useMHzunits); 32 | arma::vec GetHistogramBinCenters(); 33 | void WriteHeader(std::ostream &); // Write header for the output file 34 | 35 | protected: 36 | bool RunLocal() override; 37 | bool Validate() override; 38 | 39 | public: 40 | // Constructors / Destructors 41 | TaskActionSpectrumHistogramRPOnlyDec(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 42 | ~TaskActionSpectrumHistogramRPOnlyDec(); // Destructor 43 | }; 44 | } 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /SpinAPI/SpinAPIfwd.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ForwardDeclarations (SpinAPI Module) 3 | // ------------------ 4 | // Forward declarations of classes etc. to decrease file inter- 5 | // dependencies and speedup compilation time. 6 | // 7 | // NOTE: Make sure this file is included AFTER the other includes! 8 | // 9 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 10 | // (c) 2025 Quantum Biology and Computational Physics Group. 11 | // See LICENSE.txt for license information. 12 | ///////////////////////////////////////////////////////////////////////// 13 | #ifndef MOD_SpinAPI_ForwardDeclarations 14 | #define MOD_SpinAPI_ForwardDeclarations 15 | 16 | #include 17 | #include 18 | 19 | namespace SpinAPI 20 | { 21 | #ifndef MOD_SpinAPI_Spin 22 | class Spin; 23 | using spin_ptr = std::shared_ptr; 24 | #endif 25 | 26 | #ifndef MOD_SpinAPI_Interaction 27 | class Interaction; 28 | using interaction_ptr = std::shared_ptr; 29 | #endif 30 | 31 | #ifndef MOD_SpinAPI_Transition 32 | class Transition; 33 | using transition_ptr = std::shared_ptr; 34 | #endif 35 | 36 | #ifndef MOD_SpinAPI_Operator 37 | class Operator; 38 | using operator_ptr = std::shared_ptr; 39 | #endif 40 | 41 | #ifndef MOD_SpinAPI_Pulse 42 | class Pulse; 43 | using pulse_ptr = std::shared_ptr; 44 | #endif 45 | 46 | #ifndef MOD_SpinAPI_State 47 | class State; 48 | using state_ptr = std::shared_ptr; 49 | using StateSeries = std::vector>; 50 | using StatePair = std::pair; 51 | using CompleteState = std::vector; 52 | #endif 53 | 54 | #ifndef MOD_SpinAPI_Tensor 55 | class Tensor; 56 | #endif 57 | 58 | #ifndef MOD_SpinAPI_StandardOutput 59 | class StandardOutput; 60 | using output_ptr = std::shared_ptr; 61 | #endif 62 | 63 | #ifndef MOD_SpinAPI_SubSystem 64 | class SubSystem; 65 | using subsystem_ptr = std::shared_ptr; 66 | #endif 67 | 68 | #ifndef MOD_SpinAPI_SpinSystem 69 | class SpinSystem; 70 | using system_ptr = std::shared_ptr; 71 | #endif 72 | 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskMultiStaticSSNakajimaZwanzigTimeEvo.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskMultiStaticSSNakajimaZwanzigTimeEvo (RunSection module) 3 | // ------------------ 4 | // 5 | // Simple time-evolution calculation in Liouville space. 6 | // 7 | // -- Multi-system version: Allows transitions between SpinSystems -- 8 | // 9 | // Molecular Spin Dynamics Software - developed by Luca Gerhards. 10 | // (c) 2025 Quantum Biology and Computational Physics Group. 11 | // See LICENSE.txt for license information. 12 | ///////////////////////////////////////////////////////////////////////// 13 | #ifndef MOD_RunSection_TaskMultiStaticSSNakajimaZwanzigTimeEvo 14 | #define MOD_RunSection_TaskMultiStaticSSNakajimaZwanzigTimeEvo 15 | 16 | #include "BasicTask.h" 17 | #include "SpinSpace.h" 18 | #include "SpinSystem.h" 19 | #include "SpinAPIDefines.h" 20 | 21 | namespace RunSection 22 | { 23 | class TaskMultiStaticSSNakajimaZwanzigTimeEvo : public BasicTask 24 | { 25 | private: 26 | double timestep; 27 | double totaltime; 28 | SpinAPI::ReactionOperatorType reactionOperators; 29 | 30 | void WriteHeader(std::ostream &); // Write header for the output file 31 | 32 | // Private method that gathers and outputs the results from a given time-integrated density operator 33 | bool NakajimaZwanzigtensorTimeEvo(const arma::cx_mat &_op1, const arma::cx_mat &_op2, const arma::cx_mat &_specdens, arma::cx_mat &_NakajimaZwanzigtensor); // Contruction of NakajimaZwanzigtensor with operator basis 34 | bool ConstructSpecDensGeneralTimeEvo(const std::vector &_ampl_list, const std::vector &_tau_c_list, const arma::cx_mat &_omega, arma::cx_mat &_specdens); 35 | bool ConstructSpecDensSpecificTimeEvo(const std::complex &_ampl, const std::complex &_tau_c, const arma::cx_mat &_omega, arma::cx_mat &_specdens); 36 | 37 | protected: 38 | bool RunLocal() override; 39 | bool Validate() override; 40 | 41 | public: 42 | // Constructors / Destructors 43 | TaskMultiStaticSSNakajimaZwanzigTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 44 | ~TaskMultiStaticSSNakajimaZwanzigTimeEvo(); // Destructor 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskDynamicHSTimeEvo.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskDynamicHSTimeEvo (RunSection module) 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskDynamicHSTimeEvo 10 | #define MOD_RunSection_TaskDynamicHSTimeEvo 11 | 12 | #include "SpinSpace.h" 13 | #include "BasicTask.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskDynamicHSTimeEvo : public BasicTask 18 | { 19 | private: 20 | double timestep; 21 | double totaltime; 22 | unsigned int outputstride; 23 | bool modeQuantumYield; 24 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 25 | // If false, a quantum yield will be calculated each defined State object 26 | 27 | bool timedependentInteractions; 28 | bool timedependentTransitions; 29 | 30 | // Timestep function 31 | void AdvanceStep_AsyncLeapfrog(const arma::cx_mat &, const arma::cx_mat &, arma::cx_mat &); 32 | void OutputTimeEvolution(const SpinAPI::SpinSpace &, const arma::cx_mat &, const unsigned int, const std::vector &); 33 | void GetQuantumYields(const SpinAPI::SpinSpace &, const arma::cx_mat &, const unsigned int, const std::vector &, const std::vector &, std::map &); 34 | void OutputQuantumYields(const SpinAPI::SpinSpace &, std::map &, const unsigned int, const std::vector &, const std::vector &); 35 | void WriteHeader(std::ostream &); // Write header for the output file 36 | 37 | protected: 38 | bool RunLocal() override; 39 | bool Validate() override; 40 | 41 | public: 42 | // Constructors / Destructors 43 | TaskDynamicHSTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 44 | ~TaskDynamicHSTimeEvo(); // Destructor 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSSRedfieldTimeEvoSparse.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // MolSpin - Redfield Theory Task - developed by Luca Gerhards 3 | // 4 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 5 | // (c) 2025 Quantum Biology and Computational Physics Group. 6 | // See LICENSE.txt for license information. 7 | ////////////////////////////////////////////////////////////////////////////// 8 | #ifndef MOD_RunSection_TaskStaticSSRedfieldTimeEvoSparse 9 | #define MOD_RunSection_TaskStaticSSRedfieldTimeEvoSparse 10 | 11 | #include "BasicTask.h" 12 | #include "SpinAPIDefines.h" 13 | 14 | namespace RunSection 15 | { 16 | class TaskStaticSSRedfieldTimeEvoSparse : public BasicTask 17 | { 18 | private: 19 | double timestep; 20 | double totaltime; 21 | SpinAPI::ReactionOperatorType reactionOperators; 22 | 23 | void WriteHeader(std::ostream &); // Write header for the output file 24 | bool RedfieldtensorTimeEvoSparse(const arma::sp_cx_mat &_op1, const arma::sp_cx_mat &_op2, const arma::sp_cx_mat &_specdens, arma::sp_cx_mat &_redfieldtensor); // Contruction of Redfieldtensor with operator basis 25 | bool ConstructSpecDensGeneralTimeEvoSparse(const int &_spectral_function, const std::vector &_ampl_list, const std::vector &_tau_c_list, const arma::sp_cx_mat &_domega, arma::sp_cx_mat &_specdens); 26 | bool ConstructSpecDensSpecificTimeEvoSparse(const int &_spectral_function, const std::complex &_ampl, const std::complex &_tau_c, const arma::sp_cx_mat &_domega, arma::sp_cx_mat &_specdens); 27 | bool SlippageTimeEvoSparse(arma::sp_cx_mat **_ptr_Tensors, const int &_num_op, const arma::sp_cx_mat &_eig_val_mat, const arma::sp_cx_mat &_domega, const arma::sp_cx_mat &_rho0, const std::complex &_tau_c, arma::sp_cx_mat &_rho0_new); 28 | 29 | protected: 30 | bool RunLocal() override; 31 | bool Validate() override; 32 | 33 | public: 34 | // Constructors / Destructors 35 | TaskStaticSSRedfieldTimeEvoSparse(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 36 | ~TaskStaticSSRedfieldTimeEvoSparse(); // Destructor 37 | }; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskPeriodicHSTimeEvo.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskPeriodicHSTimeEvo (RunSection module) 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskPeriodicHSTimeEvo 10 | #define MOD_RunSection_TaskPeriodicHSTimeEvo 11 | 12 | #include "SpinSpace.h" 13 | #include "BasicTask.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskPeriodicHSTimeEvo : public BasicTask 18 | { 19 | private: 20 | double timestep; 21 | double totaltime; 22 | unsigned int stepsPerPeriod; 23 | unsigned int outputstride; 24 | bool modeQuantumYield; 25 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 26 | // If false, a quantum yield will be calculated each defined State object 27 | 28 | bool timedependentInteractions; 29 | 30 | // Timestep function 31 | void AdvanceStep_AsyncLeapfrog(const arma::cx_mat &, const arma::cx_mat &, arma::cx_mat &); 32 | void OutputTimeEvolution(const SpinAPI::SpinSpace &, const arma::cx_mat &, const unsigned int, const std::vector &); 33 | void GetQuantumYields(const SpinAPI::SpinSpace &, const arma::cx_mat &, const unsigned int, const std::vector &, const std::vector &, std::map &); 34 | void OutputQuantumYields(const SpinAPI::SpinSpace &, std::map &, const unsigned int, const std::vector &, const std::vector &); 35 | double GetPeriod(const SpinAPI::system_ptr &); 36 | void WriteHeader(std::ostream &); // Write header for the output file 37 | 38 | protected: 39 | bool RunLocal() override; 40 | bool Validate() override; 41 | 42 | public: 43 | // Constructors / Destructors 44 | TaskPeriodicHSTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 45 | ~TaskPeriodicHSTimeEvo(); // Destructor 46 | }; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /.github/workflows/c-cpp.yml: -------------------------------------------------------------------------------- 1 | name: C/C++ CI 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | release: 9 | types: [published] 10 | 11 | jobs: 12 | build: 13 | 14 | runs-on: ubuntu-latest 15 | container: ghcr.io/das0mann/molspin-build-env:dockerenv 16 | 17 | steps: 18 | - uses: actions/checkout@v4 19 | - name: ccache 20 | uses: hendrikmuhs/ccache-action@v1.2 21 | - name: make 22 | run: make CC="ccache g++ -std=c++17" -j 16 23 | - uses: actions/upload-artifact@v4 24 | with: 25 | name: Molspin Executable 26 | path: molspin 27 | - name: Upload Artifact to release 28 | if: github.event_name == 'release' 29 | run: | 30 | curl -L \ 31 | -X POST \ 32 | -H "Accept: application/vnd.github+json" \ 33 | -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ 34 | -H "X-GitHub-Api-Version: 2022-11-28" \ 35 | -H "Content-Type: application/octet-stream" \ 36 | "https://uploads.github.com/repos/${{ github.repository }}/releases/${{ github.event.release.id }}/assets?name=molspin" \ 37 | --data-binary "@molspin" 38 | 39 | deploy: 40 | runs-on: self-hosted 41 | if: github.ref == 'refs/heads/main' 42 | needs: build 43 | steps: 44 | - name: Download Artifact 45 | shell: bash 46 | run: | 47 | curl -L \ 48 | -H "Accept: application/vnd.github+json" \ 49 | -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ 50 | -H "X-GitHub-Api-Version: 2022-11-28" \ 51 | $(curl -L \ 52 | -H "Accept: application/vnd.github+json" \ 53 | -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ 54 | -H "X-GitHub-Api-Version: 2022-11-28" \ 55 | ${{ github.api_url }}/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts | \ 56 | python3 -c "import sys, json; print(json.load(sys.stdin)['artifacts'][0]['archive_download_url'])") \ 57 | -o molspin-artifact.zip 58 | - name: Unzip Artifact 59 | run: unzip -o molspin-artifact.zip 60 | - name: Copy Executable 61 | run: cp molspin /data/lxd/viking_programs/molspin/molspin -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSSRedfield.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // MolSpin - Redfield Theory Task - developed by Luca Gerhards 3 | // 4 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 5 | // (c) 2025 Quantum Biology and Computational Physics Group. 6 | // See LICENSE.txt for license information. 7 | ////////////////////////////////////////////////////////////////////////////// 8 | #ifndef MOD_RunSection_TaskStaticSSRedfield 9 | #define MOD_RunSection_TaskStaticSSRedfield 10 | 11 | #include "BasicTask.h" 12 | #include "SpinAPIDefines.h" 13 | 14 | namespace RunSection 15 | { 16 | class TaskStaticSSRedfield : public BasicTask 17 | { 18 | private: 19 | SpinAPI::ReactionOperatorType reactionOperators; 20 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 21 | // If false, a quantum yield will be calculated each defined State object 22 | 23 | void WriteHeader(std::ostream &); // Write header for the output file 24 | bool Redfieldtensor(const arma::cx_mat &_op1, const arma::cx_mat &_op2, const arma::cx_mat &_specdens, arma::cx_mat &_redfieldtensor); // Contruction of Redfieldtensor with operator basis 25 | bool ConstructSpecDensGeneral(const int &_spectral_function, const std::vector &_ampl_list, const std::vector &_tau_c_list, const arma::cx_mat &_domega, arma::cx_mat &_specdens); // Construction of Spectral Density 26 | bool ConstructSpecDensSpecific(const int &_spectral_function, const std::complex &_ampl, const std::complex &_tau_c, const arma::cx_mat &_domega, arma::cx_mat &_specdens); 27 | bool Slippage(arma::cx_mat **_ptr_Tensors, const int &_num_op, const arma::cx_mat &_eig_val_mat, const arma::cx_mat &_domega, const arma::cx_mat &_rho0, const std::complex &_tau_c, arma::cx_mat &_rho0_new); 28 | 29 | protected: 30 | bool RunLocal() override; 31 | bool Validate() override; 32 | 33 | public: 34 | // Constructors / Destructors 35 | TaskStaticSSRedfield(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 36 | ~TaskStaticSSRedfield(); // Destructor 37 | }; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticHSStochYields.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticHSStochYields (RunSection module) by Gediminas Pazera and Luca Gerhards 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskStaticHSStochYields 10 | #define MOD_RunSection_TaskStaticHSStochYields 11 | 12 | #include "BasicTask.h" 13 | #include "SpinAPIDefines.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskStaticHSStochYields : public BasicTask 18 | { 19 | private: 20 | 21 | double timestep; 22 | double totaltime; 23 | 24 | SpinAPI::ReactionOperatorType reactionOperators; 25 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 26 | // If false, a quantum yield will be calculated each defined State object 27 | arma::cx_colvec KrylovExpmGeneral(const arma::sp_cx_mat &H, const arma::cx_colvec &b, const arma::cx_double dt, int KryDim, int HilbSize); 28 | arma::cx_colvec KrylovExpmSymm(const arma::sp_cx_mat &H, const arma::cx_colvec &b, const arma::cx_double dt, int KryDim, int HilbSize); 29 | void ArnoldiProcess(const arma::sp_cx_mat &H, const arma::cx_colvec &b, arma::cx_mat &KryBasis, arma::cx_mat &Hessen, int KryDim, double &h_mplusone_m); // Produce Krylov Basis by Arnoldi Process 30 | void LanczosProcess(const arma::sp_cx_mat &H, const arma::cx_colvec &b, arma::cx_mat &KryBasis, arma::cx_mat &Hessen, int KryDim, double &h_mplusone_m); // Produce Krylov Basis by Lanczos Process 31 | void WriteHeader(std::ostream &); // Write header for the output file 32 | 33 | protected: 34 | bool RunLocal() override; 35 | bool Validate() override; 36 | 37 | public: 38 | // Constructors / Destructors 39 | TaskStaticHSStochYields(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 40 | ~TaskStaticHSStochYields(); // Destructor 41 | bool is_identity_matrix(arma::sp_cx_mat &matrix); // check if the matrix is an identity 42 | }; 43 | } 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSSRedfieldSparse.h: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // MolSpin - Redfield Theory Task - developed by Luca Gerhards 3 | // 4 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 5 | // (c) 2025 Quantum Biology and Computational Physics Group. 6 | // See LICENSE.txt for license information. 7 | ////////////////////////////////////////////////////////////////////////////// 8 | #ifndef MOD_RunSection_TaskStaticSSRedfieldSparse 9 | #define MOD_RunSection_TaskStaticSSRedfieldSparse 10 | 11 | #include "BasicTask.h" 12 | #include "SpinAPIDefines.h" 13 | 14 | namespace RunSection 15 | { 16 | class TaskStaticSSRedfieldSparse : public BasicTask 17 | { 18 | private: 19 | SpinAPI::ReactionOperatorType reactionOperators; 20 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 21 | // If false, a quantum yield will be calculated each defined State object 22 | 23 | void WriteHeader(std::ostream &); // Write header for the output file 24 | bool RedfieldtensorSparse(const arma::sp_cx_mat &_op1, const arma::sp_cx_mat &_op2, const arma::sp_cx_mat &_specdens, arma::sp_cx_mat &_redfieldtensor); // Contruction of Redfieldtensor with operator basis 25 | bool ConstructSpecDensGeneralSparse(const int &_spectral_function, const std::vector &_ampl_list, const std::vector &_tau_c_list, const arma::sp_cx_mat &_domega, arma::sp_cx_mat &_specdens); 26 | bool ConstructSpecDensSpecificSparse(const int &_spectral_function, const std::complex &_ampl, const std::complex &_tau_c, const arma::sp_cx_mat &_domega, arma::sp_cx_mat &_specdens); 27 | bool SlippageSparse(arma::sp_cx_mat **_ptr_Tensors, const int &_num_op, const arma::sp_cx_mat &_eig_val_mat, const arma::sp_cx_mat &_domega, const arma::sp_cx_mat &_rho0, const std::complex &_tau_c, arma::sp_cx_mat &_rho0_new); 28 | 29 | protected: 30 | bool RunLocal() override; 31 | bool Validate() override; 32 | 33 | public: 34 | // Constructors / Destructors 35 | TaskStaticSSRedfieldSparse(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 36 | ~TaskStaticSSRedfieldSparse(); // Destructor 37 | }; 38 | } 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSSSpectra.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticSSSpectra (RunSection module) developed by Irina Anisimova and Luca Gerhards. 3 | // ------------------ 4 | // 5 | // Simple quantum yield calculation in Liouville space, derived from the 6 | // properties of the Laplace transformation. 7 | // 8 | // Molecular Spin Dynamics Software - developed by Irina Anisimova and Luca Gerhards. 9 | // (c) 2022 Quantum Biology and Computational Physics Group. 10 | // See LICENSE.txt for license information. 11 | ///////////////////////////////////////////////////////////////////////// 12 | #ifndef MOD_RunSection_TaskStaticSSSpectra 13 | #define MOD_RunSection_TaskStaticSSSpectra 14 | 15 | #include "BasicTask.h" 16 | #include "SpinAPIDefines.h" 17 | #include "SpinSpace.h" 18 | #include "Utility.h" 19 | 20 | namespace RunSection 21 | { 22 | //Because the declaration of i is long define it as a new variable that is easier to use 23 | using SystemIterator = std::vector::const_iterator; 24 | 25 | class TaskStaticSSSpectra : public BasicTask 26 | { 27 | private: 28 | double timestep; 29 | double totaltime; 30 | SpinAPI::ReactionOperatorType reactionOperators; 31 | 32 | void WriteHeader(std::ostream &); // Write header for the output file 33 | static arma::cx_vec ComputeRhoDot(double t, arma::sp_cx_mat& L, arma::cx_vec& K, arma::cx_vec RhoNaught); 34 | bool ProjectAndPrintOutputLine(auto &_i, SpinAPI::SpinSpace &_space, arma::cx_vec &_rhovec, double &_printedtime, double _timestep, unsigned int &_n, bool &_cidsp, std::ostream &_data_stream, std::ostream &_log_stream); 35 | bool ProjectAndPrintOutputLineInf(auto &_i, SpinAPI::SpinSpace &_space, arma::cx_vec &_rhovec, double &_printedtime, double _timestep, bool &_cidsp, std::ostream &_datastream, std::ostream &_logstream); 36 | 37 | protected: 38 | bool RunLocal() override; 39 | bool Validate() override; 40 | 41 | public: 42 | // Constructors / Destructors 43 | TaskStaticSSSpectra(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 44 | ~TaskStaticSSSpectra(); // Destructor 45 | 46 | bool GetEigenvectors_H0(SpinAPI::SpinSpace &_space, arma::vec &_eigen_val, arma::sp_cx_mat &_eigen_vec_sp) const; 47 | }; 48 | 49 | } 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskMultiStaticSSRedfieldTimeEvo.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskMultiStaticSSRedfieldTimeEvo (RunSection module) 3 | // ------------------ 4 | // 5 | // Simple time-evolution calculation in Liouville space. 6 | // 7 | // -- Multi-system version: Allows transitions between SpinSystems -- 8 | // 9 | // Molecular Spin Dynamics Software - developed by Luca Gerhards. 10 | // (c) 2025 Quantum Biology and Computational Physics Group. 11 | // See LICENSE.txt for license information. 12 | ///////////////////////////////////////////////////////////////////////// 13 | #ifndef MOD_RunSection_TaskMultiStaticSSRedfieldTimeEvo 14 | #define MOD_RunSection_TaskMultiStaticSSRedfieldTimeEvo 15 | 16 | #include "BasicTask.h" 17 | #include "SpinSpace.h" 18 | #include "SpinSystem.h" 19 | #include "SpinAPIDefines.h" 20 | 21 | namespace RunSection 22 | { 23 | class TaskMultiStaticSSRedfieldTimeEvo : public BasicTask 24 | { 25 | private: 26 | double timestep; 27 | double totaltime; 28 | SpinAPI::ReactionOperatorType reactionOperators; 29 | 30 | void WriteHeader(std::ostream &); // Write header for the output file 31 | 32 | // Private method that gathers and outputs the results from a given time-integrated density operator 33 | bool Redfieldtensor(const arma::cx_mat &_op1, const arma::cx_mat &_op2, const arma::cx_mat &_specdens, arma::cx_mat &_redfieldtensor); // Contruction of Redfieldtensor with operator basis 34 | bool ConstructSpecDensGeneral(const int &_spectral_function, const std::vector &_ampl_list, const std::vector &_tau_c_list, const arma::cx_mat &_domega, arma::cx_mat &_specdens); // Construction of Spectral Density 35 | bool ConstructSpecDensSpecific(const int &_spectral_function, const std::complex &_ampl, const std::complex &_tau_c, const arma::cx_mat &_domega, arma::cx_mat &_specdens); 36 | bool Slippage(arma::cx_mat **_ptr_Tensors, const int &_num_op, const arma::cx_mat &_eig_val_mat, const arma::cx_mat &_domega, const arma::cx_mat &_rho0, const std::complex &_tau_c, arma::cx_mat &_rho0_new); 37 | 38 | protected: 39 | bool RunLocal() override; 40 | bool Validate() override; 41 | 42 | public: 43 | // Constructors / Destructors 44 | TaskMultiStaticSSRedfieldTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 45 | ~TaskMultiStaticSSRedfieldTimeEvo(); // Destructor 46 | }; 47 | } 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /RunSection/OutputHandler.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // OutputHandler (RunSection module) 3 | // ------------------ 4 | // Handles the output streams that are available to task classes. 5 | // 6 | // TODO: Consider parallel access to files when implementing MPI version. 7 | // 8 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 9 | // (c) 2025 Quantum Biology and Computational Physics Group. 10 | // See LICENSE.txt for license information. 11 | ///////////////////////////////////////////////////////////////////////// 12 | #ifndef MOD_RunSection_OutputHandler 13 | #define MOD_RunSection_OutputHandler 14 | 15 | #include 16 | #include 17 | #include 18 | #include "RunSectionDefines.h" 19 | 20 | namespace RunSection 21 | { 22 | class OutputHandler 23 | { 24 | private: 25 | // Implementation 26 | std::shared_ptr log; // File stream 27 | std::shared_ptr data; // File stream 28 | std::ostream *logstream; // Can be another type of stream 29 | std::ostream *datastream; // Can be another type of stream 30 | std::shared_ptr ignored_messages_stream; // A "garbage stream" for messages that should not be written to the other streams 31 | MessageType notificationLevel; 32 | 33 | public: 34 | // Constructors / Destructors 35 | OutputHandler(); // Normal constructor 36 | OutputHandler(const OutputHandler &) = delete; // Default Copy-constructor, no need to copy, so better delete than end up with splicing problems 37 | ~OutputHandler(); // Destructor 38 | 39 | // Operators 40 | const OutputHandler &operator=(const OutputHandler &) = delete; // Default Copy-assignment 41 | 42 | // Public methods 43 | bool SetLogFile(const std::string &_filename, bool _append = false); // Write to a file 44 | bool SetDataFile(const std::string &_filename, bool _append = false); // Write to a file 45 | bool SetLogStream(std::ostream &); // Use an existing stream (used by testing module) 46 | bool SetDataStream(std::ostream &); // Use an existing stream (used by testing module) 47 | bool SetNotificationLevel(const MessageType &); // Sets the notification level (i.e. which types of messages to show) 48 | 49 | // Public const methods 50 | std::ostream &Log(const MessageType &_msgtype = MessageType_Normal) const; 51 | std::ostream &Data() const; 52 | }; 53 | } 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /SpinAPI/StandardOutput.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // StandardOutput class (SpinAPI Module) 3 | // ------------------ 4 | // Specifier of standard output information for a spin system. 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // (c) 2025 Quantum Biology and Computational Physics Group. 8 | // See LICENSE.txt for license information. 9 | ///////////////////////////////////////////////////////////////////////// 10 | #ifndef MOD_SpinAPI_StandardOutput 11 | #define MOD_SpinAPI_StandardOutput 12 | 13 | #include 14 | #include 15 | #include "SpinAPIDefines.h" 16 | #include "ActionTarget.h" 17 | 18 | namespace SpinAPI 19 | { 20 | class StandardOutput 21 | { 22 | private: 23 | // Data members 24 | std::shared_ptr properties; // Use a pointer to the object to minimize compilation dependencies 25 | char delimiter; 26 | bool isValid; 27 | RunSection::ActionScalar *scalar; 28 | RunSection::ActionVector *vector; 29 | StandardOutputType type; 30 | arma::vec reference; 31 | std::string actionTargetName; 32 | double prefactor; 33 | 34 | // NOTE: The strings returned here should NOT contain any newline-characters! 35 | std::string Header() const; // String to write column header(s) 36 | std::string Data() const; // String to write a row in data column(s) 37 | 38 | // Private methods 39 | bool setActionVector(const std::map &); 40 | bool setActionScalar(const std::map &); 41 | 42 | public: 43 | // Constructors / Destructors 44 | StandardOutput(std::string, std::string); // Normal constructor 45 | StandardOutput(const StandardOutput &) = delete; // Copy-constructor 46 | ~StandardOutput(); // Destructor 47 | 48 | // Operators 49 | const StandardOutput operator=(const StandardOutput &) = delete; // Copy-assignment 50 | 51 | // Public methods 52 | std::string Name() const; 53 | bool IsValid() const; 54 | bool Validate(const std::map &, const std::map &); 55 | bool SetDelimiter(char); 56 | 57 | // Public output methods 58 | bool WriteOutputHeader(std::ostream &) const; // Writes the header for the output column(s) 59 | bool WriteOutput(std::ostream &) const; // Writes output data 60 | }; 61 | 62 | // Define alias for StandardOutput-pointers 63 | using output_ptr = std::shared_ptr; 64 | } 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /Tests/tests_utility.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // MolSpin Unit Testing Module 3 | // 4 | // Tests the Utility functions 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // (c) 2025 Quantum Biology and Computational Physics Group. 8 | // See LICENSE.txt for license information. 9 | ////////////////////////////////////////////////////////////////////////////// 10 | 11 | ////////////////////////////////////////////////////////////////////////////// 12 | // Add all the test cases 13 | #include "Utility.h" 14 | #include 15 | #include 16 | 17 | bool test_utility_block_solver() 18 | { 19 | const int bs = 3; 20 | const int nblk = 3; 21 | arma::cx_mat D0 = {{5.0,0.1,0.2},{0.0,6.0,0.3},{0.4,0.0,5.5}}; 22 | arma::cx_mat U0 = {{0.1,0.0,0.0},{0.0,0.2,0.1},{0.0,0.0,0.05}}; 23 | arma::cx_mat L1 = {{0.05,0.0,0.0},{0.0,0.1,0.0},{0.02,0.0,0.0}}; 24 | arma::cx_mat D1 = {{4.5,0.05,0.0},{0.0,5.5,0.1},{0.0,0.0,6.0}}; 25 | arma::cx_mat U1 = {{0.02,0.0,0.0},{0.0,0.03,0.0},{0.0,0.0,0.04}}; 26 | arma::cx_mat L2 = {{0.01,0.0,0.0},{0.0,0.02,0.0},{0.0,0.0,0.03}}; 27 | arma::cx_mat D2 = {{5.2,0.0,0.0},{0.0,4.8,0.1},{0.0,0.0,5.0}}; 28 | 29 | std::vector blk(9); 30 | // row 0 31 | blk[0] = D0; blk[1] = U0; blk[2] = arma::zeros(bs,bs); 32 | // row 1 33 | blk[3] = L1; blk[4] = D1; blk[5] = U1; 34 | // row 2 35 | blk[6] = arma::zeros(bs,bs); blk[7] = L2; blk[8] = D2; 36 | 37 | arma::sp_cx_mat A(bs*nblk, bs*nblk); 38 | for (int bi=0; bi &_cases) 63 | { 64 | _cases.push_back(test_case("Utility test 1", test_utility_block_solver)); 65 | } 66 | ////////////////////////////////////////////////////////////////////////////// -------------------------------------------------------------------------------- /RunSection/Settings.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // Settings (RunSection module) 3 | // ------------------ 4 | // Settings for a RunSection class instance, as specified in the Settings 5 | // object of the MSD input files. 6 | // 7 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 8 | // (c) 2025 Quantum Biology and Computational Physics Group. 9 | // See LICENSE.txt for license information. 10 | ///////////////////////////////////////////////////////////////////////// 11 | #ifndef MOD_RunSection_Settings 12 | #define MOD_RunSection_Settings 13 | 14 | #include "MSDParserfwd.h" 15 | #include "RunSectionDefines.h" 16 | #include "ActionTarget.h" 17 | 18 | namespace RunSection 19 | { 20 | class Settings 21 | { 22 | private: 23 | // Implementation 24 | unsigned int steps; 25 | unsigned int currentStep; 26 | char dataDelimiter; 27 | MessageType notificationLevel; 28 | double time; 29 | unsigned int trajectoryStep; 30 | bool setTrajectoryStepBeforeTime; 31 | //bool m_Parallelize; 32 | 33 | public: 34 | // Constructors / Destructors 35 | Settings(); // Normal constructor 36 | Settings(const Settings &); // Default Copy-constructor, no need to copy, so better delete than end up with splicing problems 37 | ~Settings(); // Destructor 38 | 39 | // Operators 40 | const Settings &operator=(const Settings &); // Default Copy-assignment 41 | 42 | // Update method 43 | void Update(const MSDParser::ObjectParser &); 44 | 45 | // Public methods to change parameters 46 | void SetCurrentStep(unsigned int); 47 | 48 | // Public const methods 49 | unsigned int Steps() const { return this->steps; }; 50 | unsigned int CurrentStep() const { return this->currentStep; }; 51 | char DataDelimiter() const { return this->dataDelimiter; }; 52 | MessageType NotificationLevel() const { return this->notificationLevel; }; 53 | double Time() const { return this->time; }; 54 | unsigned int TrajectoryStep() const { return this->trajectoryStep; }; 55 | bool SetTrajectoryStepBeforeTime() const { return this->setTrajectoryStepBeforeTime; }; 56 | //bool GetParallel() const { return this->m_Parallelize; }; 57 | 58 | // Method to define ActionTargets for the Settings object 59 | void GetActionTargets(std::map &, std::map &); 60 | 61 | // Default values 62 | const unsigned int DefaultSteps = 1; 63 | const double DefaultTime = 0.0; 64 | const unsigned int DefaultTrajectoryStep = 0; 65 | }; 66 | 67 | // Non-member non-friend functions for ActionTarget validation 68 | bool CheckActionScalarSettingsTime(const double &); 69 | } 70 | 71 | #endif 72 | -------------------------------------------------------------------------------- /RunSection/Action.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // Action (RunSection module) 3 | // ------------------ 4 | // Base class for Actions that can be triggered between calculation steps 5 | // in order to change parameters of the spin system. 6 | // 7 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 8 | // (c) 2025 Quantum Biology and Computational Physics Group. 9 | // See LICENSE.txt for license information. 10 | ///////////////////////////////////////////////////////////////////////// 11 | #ifndef MOD_RunSection_Action 12 | #define MOD_RunSection_Action 13 | 14 | #include 15 | #include 16 | #include "MSDParserfwd.h" 17 | #include "ActionTarget.h" 18 | 19 | namespace RunSection 20 | { 21 | class Action 22 | { 23 | private: 24 | // Data members 25 | std::shared_ptr properties; // Use a pointer to the object to minimize compilation dependencies 26 | const std::map &scalars; 27 | const std::map &vectors; 28 | bool isValid; 29 | double value; 30 | unsigned int first; 31 | unsigned int last; 32 | unsigned int period; 33 | bool m_loop; 34 | //bool m_Parallelize; 35 | 36 | protected: 37 | // Protected methods 38 | std::shared_ptr Properties() const { return this->properties; }; 39 | bool Scalar(std::string _name, ActionScalar **_scalar = nullptr) const; 40 | bool Vector(std::string _name, ActionVector **_vector = nullptr) const; 41 | 42 | // Methods to be overwritten in derived classes 43 | virtual bool DoStep() = 0; 44 | virtual bool DoValidate() = 0; 45 | virtual bool Reset() = 0; 46 | 47 | public: 48 | // Constructors / Destructors 49 | Action(const MSDParser::ObjectParser &, const std::map &, const std::map &); // Normal constructor 50 | Action(const Action &) = delete; // Default Copy-constructor, no need to copy, so better delete than end up with splicing problems 51 | virtual ~Action(); // Destructor 52 | 53 | // Operators 54 | Action &operator=(const Action &) = delete; // Default Copy-assignment 55 | 56 | // Public methods 57 | double Value() const; 58 | unsigned int First() const; 59 | unsigned int Last() const; 60 | unsigned int Period() const; 61 | void Step(unsigned int); 62 | bool IsValid() const; 63 | std::string Name(); 64 | //bool GetParallel() const { return this->m_Parallelize; }; 65 | 66 | const std::shared_ptr GetProperties() const { return this->properties; }; 67 | 68 | // Public method to be overwritten 69 | bool Validate(); 70 | }; 71 | } 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSSSpectraNakajimaZwanzig.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticSSSpectraNakajimaZwanzig (RunSection module) developed by Irina Anisimova and Luca Gerhards. 3 | // ------------------ 4 | // 5 | // Simple quantum yield calculation in Liouville space, derived from the 6 | // properties of the Laplace transformation. 7 | // 8 | // Molecular Spin Dynamics Software - developed by Irina Anisimova and Luca Gerhards. 9 | // (c) 2022 Quantum Biology and Computational Physics Group. 10 | // See LICENSE.txt for license information. 11 | ///////////////////////////////////////////////////////////////////////// 12 | #ifndef MOD_RunSection_TaskStaticSSSpectraNakajimaZwanzig 13 | #define MOD_RunSection_TaskStaticSSSpectraNakajimaZwanzig 14 | 15 | #include "BasicTask.h" 16 | #include "SpinAPIDefines.h" 17 | #include "SpinSpace.h" 18 | 19 | namespace RunSection 20 | { 21 | //Because the declaration of i is long define it as a new variable that is easier to use 22 | using SystemIterator = std::vector::const_iterator; 23 | 24 | class TaskStaticSSSpectraNakajimaZwanzig : public BasicTask 25 | { 26 | private: 27 | double timestep; 28 | double totaltime; 29 | SpinAPI::ReactionOperatorType reactionOperators; 30 | 31 | void WriteHeader(std::ostream &); // Write header for the output file 32 | 33 | bool NakajimaZwanzigtensorSpectra(const arma::cx_mat &_op1, const arma::cx_mat &_op2, const arma::cx_mat &_specdens, arma::cx_mat &_NakajimaZwanzigtensor); // Contruction of NakajimaZwanzigtensor with operator basis 34 | bool ConstructSpecDensGeneralSpectra(const std::vector &_ampl_list, const std::vector &_tau_c_list, const arma::cx_mat &_omega, arma::cx_mat &_specdens); 35 | bool ConstructSpecDensSpecificSpectra(const std::complex &_ampl, const std::complex &_tau_c, const arma::cx_mat &_omega, arma::cx_mat &_specdens); 36 | 37 | bool ProjectAndPrintOutputLine(auto &_i, SpinAPI::SpinSpace &_space, arma::cx_vec &_rhovec, arma::cx_mat &_rotationmtx, double &_printedtime, double _timestep, unsigned int &_n, bool &_cidsp, std::ostream &_data_stream, std::ostream &_log_stream); 38 | bool ProjectAndPrintOutputLineInf(auto &_i, SpinAPI::SpinSpace &_space, arma::cx_vec &_rhovec, arma::cx_mat &_rotationmtx, double &_printedtime, double _timestep, bool &_cidsp, std::ostream &_datastream, std::ostream &_logstream); 39 | 40 | protected: 41 | bool RunLocal() override; 42 | bool Validate() override; 43 | 44 | public: 45 | // Constructors / Destructors 46 | TaskStaticSSSpectraNakajimaZwanzig(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 47 | ~TaskStaticSSSpectraNakajimaZwanzig(); // Destructor 48 | }; 49 | 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /MSDParser/ObjectParser.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ObjectParser class (MSDParser Module) 3 | // ------------------ 4 | // Parses the contents of objects, to provide easy access to object 5 | // contents for the SpinAPI classes. 6 | // 7 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 8 | // (c) 2025 Quantum Biology and Computational Physics Group. 9 | // See LICENSE.txt for license information. 10 | ///////////////////////////////////////////////////////////////////////// 11 | #ifndef MOD_MSDParser_ObjectParser 12 | #define MOD_MSDParser_ObjectParser 13 | 14 | #include 15 | #include 16 | #include 17 | #include "SpinAPIfwd.h" 18 | 19 | namespace MSDParser 20 | { 21 | class ObjectParser 22 | { 23 | private: 24 | // Implementation 25 | std::map fields; 26 | std::string name; 27 | 28 | public: 29 | // Constructors / Destructors 30 | ObjectParser(std::string, std::string); // Normal constructor 31 | ObjectParser(const ObjectParser &); // Default Copy-constructor 32 | ~ObjectParser(); // Destructor 33 | 34 | // Operators 35 | ObjectParser &operator=(const ObjectParser &); // Default Copy-assignment 36 | // Public methods to get a property 37 | bool Get(const std::string &, std::string &) const; 38 | bool Get(const std::string &, double &) const; 39 | bool Get(const std::string &, unsigned int &) const; 40 | bool Get(const std::string &, int &) const; 41 | bool Get(const std::string &, bool &) const; 42 | bool Get(const std::string &, SpinAPI::Tensor &) const; 43 | bool Get(const std::string &, arma::vec &) const; 44 | bool GetList(const std::string &, std::vector &, const char &_delimiter = ',') const; 45 | bool GetList(const std::string &, std::vector &, const char &_delimiter = ',') const; 46 | bool GetList(const std::string &, std::vector &, const char &_delimiter = ',') const; 47 | bool GetList(const std::string &, std::vector &, const char &_delimiter = ',') const; 48 | bool GetList(const std::string &, std::vector &, const char &_delimiter = ',') const; 49 | bool GetList(const std::string &, std::vector &, const char &_delimiter = ',') const; 50 | bool GetMatrix(const std::string &_str, arma::mat &_out) const; 51 | bool GetPulseSequence(const std::string &_str, std::vector> &_out) const; 52 | bool GetSpin(const std::string &, unsigned int &) const; // Allows for notation such as "1/2"->1, "1"->2, "3/2"->3, etc. 53 | 54 | std::vector> GetFunction(std::string) const; // TODO: Invent a better name for this method 55 | 56 | std::string Name() const; 57 | }; 58 | } 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /RunSection/Actions/ActionAddScalar.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ActionAddScalar implementation (RunSection module) 3 | // 4 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 5 | // (c) 2025 Quantum Biology and Computational Physics Group. 6 | // See LICENSE.txt for license information. 7 | ///////////////////////////////////////////////////////////////////////// 8 | #include "ActionAddScalar.h" 9 | #include "ObjectParser.h" 10 | 11 | namespace RunSection 12 | { 13 | // ----------------------------------------------------- 14 | // ActionAddScalar Constructors and Destructor 15 | // ----------------------------------------------------- 16 | ActionAddScalar::ActionAddScalar(const MSDParser::ObjectParser &_parser, const std::map &_scalars, const std::map &_vectors) : Action(_parser, _scalars, _vectors), actionScalar(nullptr) 17 | { 18 | } 19 | 20 | ActionAddScalar::~ActionAddScalar() 21 | { 22 | } 23 | // ----------------------------------------------------- 24 | // ActionAddScalar derived methods 25 | // ----------------------------------------------------- 26 | // Method to perform a step 27 | bool ActionAddScalar::DoStep() 28 | { 29 | // Make sure we have an ActionScalar to act on 30 | if (actionScalar == nullptr || !this->IsValid()) 31 | { 32 | return false; 33 | } 34 | 35 | // Retrieve the scalar we want to change 36 | double d = actionScalar->Get(); 37 | 38 | // Set the new scalar 39 | return this->actionScalar->Set(d + this->Value()); 40 | } 41 | 42 | // Method to prepare the action and check whether it is valid 43 | bool ActionAddScalar::DoValidate() 44 | { 45 | // Get the ActionScalar name 46 | std::string str; 47 | if (!this->Properties()->Get("actionscalar", str) && !this->Properties()->Get("scalar", str)) 48 | { 49 | std::cout << "ERROR: No ActionScalar specified for the AddScalar action \"" << this->Name() << "\"!" << std::endl; 50 | return false; 51 | } 52 | 53 | // Attemp to set the ActionScalar 54 | if (!this->Scalar(str, &(this->actionScalar))) 55 | { 56 | std::cout << "ERROR: Could not find ActionScalar \"" << str << "\" specified for the AddScalar action \"" << this->Name() << "\"!" << std::endl; 57 | return false; 58 | } 59 | 60 | // Readonly ActionTargets cannot be acted on 61 | if (this->actionScalar->IsReadonly()) 62 | { 63 | std::cout << "ERROR: Readonly ActionScalar \"" << str << "\" specified for the AddScalar action \"" << this->Name() << "\"! Cannot act on this scalar!" << std::endl; 64 | return false; 65 | } 66 | 67 | return true; 68 | } 69 | 70 | bool ActionAddScalar::Reset() 71 | { 72 | this->actionScalar->Reset(); 73 | return true; 74 | } 75 | // ----------------------------------------------------- 76 | } 77 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticRPOnlyHSSymDecRedfield.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticHSSymmetricDecay (RunSection module) 3 | // ------------------ 4 | // Hilbert space method. Assummes symmetric (spin independent) recombination. 5 | // Note: Also assumes that we have a radical pair with non-interacting spins! 6 | // 7 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 8 | // (c) 2025 Quantum Biology and Computational Physics Group. 9 | // See LICENSE.txt for license information. 10 | ///////////////////////////////////////////////////////////////////////// 11 | #ifndef MOD_RunSection_TaskStaticRPOnlyHSSymDecRedfield 12 | #define MOD_RunSection_TaskStaticRPOnlyHSSymDecRedfield 13 | 14 | #include "SpinSpace.h" 15 | #include "BasicTask.h" 16 | 17 | namespace RunSection 18 | { 19 | class TaskStaticRPOnlyHSSymDecRedfield : public BasicTask 20 | { 21 | private: 22 | bool modeQuantumYield; 23 | bool productYieldsOnly; // If true, a quantum yield will be calculated from each Transition object and multiplied by the rate constant 24 | double timestep; 25 | double totaltime; 26 | // If false, a quantum yield will be calculated each defined State object 27 | 28 | void WriteHeader(std::ostream &); // Write header for the output file 29 | void GetQuantumYields(const SpinAPI::SpinSpace &_space, const arma::cx_mat &_rho, const unsigned int _step, const std::vector &_states, const std::vector &_transitions, std::map &_yields); 30 | void OutputQuantumYields(const SpinAPI::SpinSpace &_space, std::map &_yields, const unsigned int _steps, const std::vector &_states, const std::vector &_transitions); 31 | 32 | bool Redfieldtensor(const arma::cx_mat &_op1, const arma::cx_mat &_op2, const arma::cx_mat &_specdens, arma::cx_mat &_redfieldtensor); 33 | bool ConstructSpecDensGeneral(const int &_spectral_function, const std::vector &_ampl_list, const std::vector &_tau_c_list, const arma::cx_mat &_domega, arma::cx_mat &_specdens); 34 | bool ConstructSpecDensSpecific(const int &_spectral_function, const std::complex &_ampl, const std::complex &_tau_c, const arma::cx_mat &_domega, arma::cx_mat &_specdens); 35 | bool Slippage(arma::cx_mat **_ptr_Tensors, const int &_num_op, const arma::cx_mat &_eig_val_mat, const arma::cx_mat &_domega, const arma::cx_mat &_rho0, const std::complex &_tau_c, arma::cx_mat &_rho0_new); 36 | 37 | protected: 38 | bool RunLocal() override; 39 | bool Validate() override; 40 | 41 | public: 42 | // Constructors / Destructors 43 | TaskStaticRPOnlyHSSymDecRedfield(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 44 | ~TaskStaticRPOnlyHSSymDecRedfield(); // Destructor 45 | }; 46 | } 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /RunSection/Actions/ActionMultiplyScalar.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ActionMultiplyScalar implementation (RunSection module) 3 | // 4 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 5 | // (c) 2025 Quantum Biology and Computational Physics Group. 6 | // See LICENSE.txt for license information. 7 | ///////////////////////////////////////////////////////////////////////// 8 | #include "ActionMultiplyScalar.h" 9 | #include "ObjectParser.h" 10 | 11 | namespace RunSection 12 | { 13 | // ----------------------------------------------------- 14 | // ActionMultiplyScalar Constructors and Destructor 15 | // ----------------------------------------------------- 16 | ActionMultiplyScalar::ActionMultiplyScalar(const MSDParser::ObjectParser &_parser, const std::map &_scalars, const std::map &_vectors) : Action(_parser, _scalars, _vectors), actionScalar(nullptr) 17 | { 18 | } 19 | 20 | ActionMultiplyScalar::~ActionMultiplyScalar() 21 | { 22 | } 23 | // ----------------------------------------------------- 24 | // ActionMultiplyScalar derived methods 25 | // ----------------------------------------------------- 26 | // Method to perform a step 27 | bool ActionMultiplyScalar::DoStep() 28 | { 29 | // Make sure we have an ActionScalar to act on 30 | if (actionScalar == nullptr || !this->IsValid()) 31 | { 32 | return false; 33 | } 34 | 35 | // Retrieve the scalar we want to change 36 | double d = actionScalar->Get(); 37 | 38 | // Set the new scalar 39 | return this->actionScalar->Set(d * this->Value()); 40 | } 41 | 42 | // Method to prepare the action and check whether it is valid 43 | bool ActionMultiplyScalar::DoValidate() 44 | { 45 | // Get the ActionScalar name 46 | std::string str; 47 | if (!this->Properties()->Get("actionscalar", str) && !this->Properties()->Get("scalar", str)) 48 | { 49 | std::cout << "ERROR: No ActionScalar specified for the MultiplyScalar action \"" << this->Name() << "\"!" << std::endl; 50 | return false; 51 | } 52 | 53 | // Attemp to set the ActionScalar 54 | if (!this->Scalar(str, &(this->actionScalar))) 55 | { 56 | std::cout << "ERROR: Could not find ActionScalar \"" << str << "\" specified for the MultiplyScalar action \"" << this->Name() << "\"!" << std::endl; 57 | return false; 58 | } 59 | 60 | // Readonly ActionTargets cannot be acted on 61 | if (this->actionScalar->IsReadonly()) 62 | { 63 | std::cout << "ERROR: Readonly ActionScalar \"" << str << "\" specified for the MultiplyScalar action \"" << this->Name() << "\"! Cannot act on this scalar!" << std::endl; 64 | return false; 65 | } 66 | 67 | return true; 68 | } 69 | 70 | bool ActionMultiplyScalar::Reset() 71 | { 72 | this->actionScalar->Reset(); 73 | return true; 74 | } 75 | // ----------------------------------------------------- 76 | } 77 | -------------------------------------------------------------------------------- /RunSection/Actions/ActionScaleVector.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ActionScaleVector implementation (RunSection module) 3 | // 4 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 5 | // (c) 2025 Quantum Biology and Computational Physics Group. 6 | // See LICENSE.txt for license information. 7 | ///////////////////////////////////////////////////////////////////////// 8 | #include "ActionScaleVector.h" 9 | #include "ObjectParser.h" 10 | 11 | namespace RunSection 12 | { 13 | // ----------------------------------------------------- 14 | // ActionScaleVector Constructors and Destructor 15 | // ----------------------------------------------------- 16 | ActionScaleVector::ActionScaleVector(const MSDParser::ObjectParser &_parser, const std::map &_scalars, const std::map &_vectors) : Action(_parser, _scalars, _vectors), actionVector(nullptr) 17 | { 18 | } 19 | 20 | ActionScaleVector::~ActionScaleVector() 21 | { 22 | } 23 | // ----------------------------------------------------- 24 | // ActionScaleVector derived methods 25 | // ----------------------------------------------------- 26 | // Method to perform a step 27 | bool ActionScaleVector::DoStep() 28 | { 29 | // Make sure we have an ActionVector to act on 30 | if (actionVector == nullptr || !this->IsValid()) 31 | { 32 | return false; 33 | } 34 | 35 | // Retrieve the vector we want to scale 36 | arma::vec vec = actionVector->Get(); 37 | 38 | // Scale the vector 39 | vec *= this->Value(); 40 | 41 | // Set the new vector 42 | return this->actionVector->Set(vec); 43 | } 44 | 45 | // Method to prepare the action and check whether it is valid 46 | bool ActionScaleVector::DoValidate() 47 | { 48 | // Get the ActionVector name 49 | std::string str; 50 | if (!this->Properties()->Get("actionvector", str) && !this->Properties()->Get("vector", str)) 51 | { 52 | std::cout << "ERROR: No ActionVector specified for the ScaleVector action \"" << this->Name() << "\"!" << std::endl; 53 | return false; 54 | } 55 | 56 | // Attemp to set the ActionVector 57 | if (!this->Vector(str, &(this->actionVector))) 58 | { 59 | std::cout << "ERROR: Could not find ActionVector \"" << str << "\" specified for the ScaleVector action \"" << this->Name() << "\"!" << std::endl; 60 | return false; 61 | } 62 | 63 | // Readonly ActionTargets cannot be acted on 64 | if (this->actionVector->IsReadonly()) 65 | { 66 | std::cout << "ERROR: Readonly ActionVector \"" << str << "\" specified for the ScaleVector action \"" << this->Name() << "\"! Cannot act on this vector!" << std::endl; 67 | return false; 68 | } 69 | 70 | return true; 71 | } 72 | 73 | bool ActionScaleVector::Reset() 74 | { 75 | this->actionVector->Reset(); 76 | return true; 77 | } 78 | // ----------------------------------------------------- 79 | } 80 | -------------------------------------------------------------------------------- /Example/magnetoreception/timeevolution/example_2.msd: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------- 2 | // Simple time-evolution calculation on a radical pair. 3 | // Contains the N5 nucleus on FAD. May apply an oscillating magnetic field. 4 | // ------------------------------------------------------------- 5 | SpinSystem RPSystem 6 | { 7 | 8 | // --------------------------------------------------------- 9 | // Spins 10 | // --------------------------------------------------------- 11 | 12 | Spin FADN5 13 | { 14 | // Hyperfine tensor from: 15 | // "The quantum needle of the avian magnetic compass." 16 | // H. G. Hiscock et al. PNAS, 113, 4634-4639 (2016) 17 | tensor = matrix("-0.0989 0.0039 0.0;0.0039 -0.0881 0.0;0.0 0.0 1.7569"); 18 | spin = 1; 19 | } 20 | 21 | Spin RPElectron1 22 | { 23 | type = electron; 24 | tensor = isotropic(2); 25 | spin = 1/2; 26 | } 27 | 28 | Spin RPElectron2 29 | { 30 | type = electron; 31 | tensor = isotropic(2); 32 | spin = 1/2; 33 | } 34 | 35 | // --------------------------------------------------------- 36 | // Interactions 37 | // --------------------------------------------------------- 38 | Interaction radical1hyperfine 39 | { 40 | prefactor = 0.001; // Convert T to mT 41 | type = hyperfine; 42 | group1 = RPElectron1; 43 | group2 = FADN5; 44 | tensor = isotropic(1); 45 | } 46 | 47 | Interaction zeeman1 48 | { 49 | prefactor = 0.001; // Convert T to mT 50 | type = zeeman; 51 | field = "0.0 0.035355339 0.035355339 "; 52 | spins = RPElectron1,RPElectron2; 53 | } 54 | 55 | // --------------------------------------------------------- 56 | // Spin States 57 | // --------------------------------------------------------- 58 | State Singlet // |S> 59 | { 60 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> - |-1/2,1/2>; 61 | } 62 | 63 | State T0 // |T0> 64 | { 65 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> + |-1/2,1/2>; 66 | } 67 | 68 | State Tp // |T+> 69 | { 70 | spin(RPElectron2) = |1/2>; 71 | spin(RPElectron1) = |1/2>; 72 | } 73 | 74 | State Tm // |T-> 75 | { 76 | spin(RPElectron2) = |-1/2>; 77 | spin(RPElectron1) = |-1/2>; 78 | } 79 | 80 | State Identity // Identity projection 81 | { 82 | } 83 | 84 | // --------------------------------------------------------- 85 | // SpinSystem Properties 86 | // --------------------------------------------------------- 87 | Properties properties 88 | { 89 | Initialstate = Singlet; 90 | } 91 | } 92 | // ------------------------------------------------------------- 93 | Settings 94 | { 95 | Settings general 96 | { 97 | steps = 1; //88; 98 | notifications = details; 99 | } 100 | 101 | } 102 | // ------------------------------------------------------------- 103 | Run 104 | { 105 | Task Method2 106 | { 107 | type = "staticss-timeevolution"; 108 | logfile = "example_timeevolution.log"; 109 | datafile = "example_timeevolution.dat"; 110 | Timestep = 0.01; 111 | TotalTime = 1000; 112 | 113 | } 114 | 115 | } 116 | 117 | -------------------------------------------------------------------------------- /Example/magnetoreception/timeevolution/example_2_5_ps.msd: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------- 2 | // Simple time-evolution calculation on a radical pair. 3 | // Contains the N5 nucleus on FAD. May apply an oscillating magnetic field. 4 | // ------------------------------------------------------------- 5 | SpinSystem RPSystem 6 | { 7 | 8 | // --------------------------------------------------------- 9 | // Spins 10 | // --------------------------------------------------------- 11 | 12 | Spin FADN5 13 | { 14 | // Hyperfine tensor from: 15 | // "The quantum needle of the avian magnetic compass." 16 | // H. G. Hiscock et al. PNAS, 113, 4634-4639 (2016) 17 | tensor = matrix("-0.0989 0.0039 0.0;0.0039 -0.0881 0.0;0.0 0.0 1.7569"); 18 | spin = 1; 19 | } 20 | 21 | Spin RPElectron1 22 | { 23 | type = electron; 24 | spin = 1/2; 25 | } 26 | 27 | Spin RPElectron2 28 | { 29 | type = electron; 30 | spin = 1/2; 31 | } 32 | 33 | // --------------------------------------------------------- 34 | // Interactions 35 | // --------------------------------------------------------- 36 | Interaction radical1hyperfine 37 | { 38 | prefactor = 0.001; // Convert T to mT 39 | type = hyperfine; 40 | group1 = RPElectron1; 41 | group2 = FADN5; 42 | tensor = isotropic(1); 43 | tau_c = 0.005; 44 | g = 1; 45 | ops = 0; 46 | coeff = 1; 47 | } 48 | 49 | Interaction zeeman1 50 | { 51 | prefactor = 0.001; // Convert T to mT 52 | type = zeeman; 53 | field = "0.0 0.035355339 0.035355339 "; 54 | spins = RPElectron1,RPElectron2; 55 | tensor = isotropic(2); 56 | } 57 | 58 | // --------------------------------------------------------- 59 | // Spin States 60 | // --------------------------------------------------------- 61 | State Singlet // |S> 62 | { 63 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> - |-1/2,1/2>; 64 | } 65 | 66 | State T0 // |T0> 67 | { 68 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> + |-1/2,1/2>; 69 | } 70 | 71 | State Tp // |T+> 72 | { 73 | spin(RPElectron2) = |1/2>; 74 | spin(RPElectron1) = |1/2>; 75 | } 76 | 77 | State Tm // |T-> 78 | { 79 | spin(RPElectron2) = |-1/2>; 80 | spin(RPElectron1) = |-1/2>; 81 | } 82 | 83 | State Identity // Identity projection 84 | { 85 | } 86 | 87 | // --------------------------------------------------------- 88 | // SpinSystem Properties 89 | // --------------------------------------------------------- 90 | Properties properties 91 | { 92 | Initialstate = Singlet; 93 | } 94 | } 95 | // ------------------------------------------------------------- 96 | Settings 97 | { 98 | Settings general 99 | { 100 | steps = 1; //88; 101 | notifications = details; 102 | } 103 | 104 | } 105 | // ------------------------------------------------------------- 106 | Run 107 | { 108 | Task Method1 109 | { 110 | type = redfield-relaxation-timeevolution; 111 | logfile = "redfield-relaxation-timeevolution.log"; 112 | datafile = "redfield-relaxation-timeevolution.dat"; 113 | Timestep = 0.01; 114 | TotalTime = 1000; 115 | 116 | } 117 | 118 | } 119 | 120 | -------------------------------------------------------------------------------- /Example/magnetoreception/timeevolution/example_2_50_ps.msd: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------- 2 | // Simple time-evolution calculation on a radical pair. 3 | // Contains the N5 nucleus on FAD. May apply an oscillating magnetic field. 4 | // ------------------------------------------------------------- 5 | SpinSystem RPSystem 6 | { 7 | 8 | // --------------------------------------------------------- 9 | // Spins 10 | // --------------------------------------------------------- 11 | 12 | Spin FADN5 13 | { 14 | // Hyperfine tensor from: 15 | // "The quantum needle of the avian magnetic compass." 16 | // H. G. Hiscock et al. PNAS, 113, 4634-4639 (2016) 17 | tensor = matrix("-0.0989 0.0039 0.0;0.0039 -0.0881 0.0;0.0 0.0 1.7569"); 18 | spin = 1; 19 | } 20 | 21 | Spin RPElectron1 22 | { 23 | type = electron; 24 | tensor = isotropic(2); 25 | spin = 1/2; 26 | } 27 | 28 | Spin RPElectron2 29 | { 30 | type = electron; 31 | tensor = isotropic(2); 32 | spin = 1/2; 33 | } 34 | 35 | // --------------------------------------------------------- 36 | // Interactions 37 | // --------------------------------------------------------- 38 | Interaction radical1hyperfine 39 | { 40 | prefactor = 0.001; // Convert T to mT 41 | type = hyperfine; 42 | group1 = RPElectron1; 43 | group2 = FADN5; 44 | tensor = isotropic(1); 45 | tau_c = 0.05; 46 | g = 1; 47 | ops = 0; 48 | coeff = 1; 49 | } 50 | 51 | Interaction zeeman1 52 | { 53 | prefactor = 0.001; // Convert T to mT 54 | type = zeeman; 55 | field = "0.0 0.035355339 0.035355339 "; 56 | spins = RPElectron1,RPElectron2; 57 | } 58 | 59 | // --------------------------------------------------------- 60 | // Spin States 61 | // --------------------------------------------------------- 62 | State Singlet // |S> 63 | { 64 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> - |-1/2,1/2>; 65 | } 66 | 67 | State T0 // |T0> 68 | { 69 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> + |-1/2,1/2>; 70 | } 71 | 72 | State Tp // |T+> 73 | { 74 | spin(RPElectron2) = |1/2>; 75 | spin(RPElectron1) = |1/2>; 76 | } 77 | 78 | State Tm // |T-> 79 | { 80 | spin(RPElectron2) = |-1/2>; 81 | spin(RPElectron1) = |-1/2>; 82 | } 83 | 84 | State Identity // Identity projection 85 | { 86 | } 87 | 88 | // --------------------------------------------------------- 89 | // SpinSystem Properties 90 | // --------------------------------------------------------- 91 | Properties properties 92 | { 93 | Initialstate = Singlet; 94 | } 95 | } 96 | // ------------------------------------------------------------- 97 | Settings 98 | { 99 | Settings general 100 | { 101 | steps = 1; //88; 102 | notifications = details; 103 | } 104 | 105 | } 106 | // ------------------------------------------------------------- 107 | Run 108 | { 109 | Task Method1 110 | { 111 | type = redfield-relaxation-timeevolution; 112 | logfile = "redfield-relaxation-timeevolution.log"; 113 | datafile = "redfield-relaxation-timeevolution.dat"; 114 | Timestep = 0.01; 115 | TotalTime = 1000; 116 | } 117 | } 118 | 119 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskMultiDynamicHSTimeEvo.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskMultiDynamicHSTimeEvo (RunSection module) 3 | // ------------------ 4 | // 5 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 6 | // (c) 2025 Quantum Biology and Computational Physics Group. 7 | // See LICENSE.txt for license information. 8 | ///////////////////////////////////////////////////////////////////////// 9 | #ifndef MOD_RunSection_TaskMultiDynamicHSTimeEvo 10 | #define MOD_RunSection_TaskMultiDynamicHSTimeEvo 11 | 12 | #include "SpinSpace.h" 13 | #include "BasicTask.h" 14 | 15 | namespace RunSection 16 | { 17 | class TaskMultiDynamicHSTimeEvo : public BasicTask 18 | { 19 | private: 20 | double timestep; 21 | double totaltime; 22 | unsigned int outputstride; 23 | 24 | // Method to obtain creation operators 25 | void GetCreationOperators(const std::vector, std::shared_ptr>> &, 26 | std::vector &, const std::vector &); 27 | 28 | // Timestep function 29 | void AdvanceStep_AsyncLeapfrog(const std::vector, std::shared_ptr>> &, 30 | const std::vector &, const std::vector &, 31 | const std::vector &, const std::vector &, 32 | const std::vector &, std::vector &); 33 | 34 | void AdvanceStep_RK4(const std::vector, std::shared_ptr>> &_spaces, 35 | const std::vector &_H, const std::vector &_dH, 36 | const std::vector &_K, const std::vector &_dK, 37 | const std::vector &_C, std::vector &_rho); 38 | 39 | arma::cx_mat ComputeRhoDot(const arma::cx_mat &H, const arma::sp_cx_mat &dH, 40 | const arma::cx_mat &K, const arma::sp_cx_mat &dK, 41 | const arma::sp_cx_mat &C, const arma::cx_mat &rho); 42 | 43 | // Method to obtain the results from the current state 44 | void OutputResults(const std::vector, std::shared_ptr>> &, const std::vector &, const unsigned int); 45 | 46 | // Method to update time-dependent interactions or reactions 47 | void UpdateTimeDependences(const std::vector, std::shared_ptr>> &, 48 | std::vector &, std::vector &, unsigned int); 49 | 50 | // Write header for the output file 51 | void WriteHeader(std::ostream &); 52 | 53 | protected: 54 | bool RunLocal() override; 55 | bool Validate() override; 56 | 57 | public: 58 | // Constructors / Destructors 59 | TaskMultiDynamicHSTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 60 | ~TaskMultiDynamicHSTimeEvo(); // Destructor 61 | }; 62 | } 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /Example/magnetoreception/timeevolution/example_2_500_ps.msd: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------- 2 | // Simple time-evolution calculation on a radical pair. 3 | // Contains the N5 nucleus on FAD. May apply an oscillating magnetic field. 4 | // ------------------------------------------------------------- 5 | SpinSystem RPSystem 6 | { 7 | 8 | // --------------------------------------------------------- 9 | // Spins 10 | // --------------------------------------------------------- 11 | 12 | Spin FADN5 13 | { 14 | // Hyperfine tensor from: 15 | // "The quantum needle of the avian magnetic compass." 16 | // H. G. Hiscock et al. PNAS, 113, 4634-4639 (2016) 17 | tensor = matrix("-0.0989 0.0039 0.0;0.0039 -0.0881 0.0;0.0 0.0 1.7569"); 18 | spin = 1; 19 | } 20 | 21 | Spin RPElectron1 22 | { 23 | type = electron; 24 | tensor = isotropic(2); 25 | spin = 1/2; 26 | } 27 | 28 | Spin RPElectron2 29 | { 30 | type = electron; 31 | tensor = isotropic(2); 32 | spin = 1/2; 33 | } 34 | 35 | // --------------------------------------------------------- 36 | // Interactions 37 | // --------------------------------------------------------- 38 | Interaction radical1hyperfine 39 | { 40 | prefactor = 0.001; // Convert T to mT 41 | type = hyperfine; 42 | group1 = RPElectron1; 43 | group2 = FADN5; 44 | tensor = isotropic(1); 45 | tau_c = 0.5; 46 | g = 1; 47 | ops = 0; 48 | coeff = 1; 49 | } 50 | 51 | Interaction zeeman1 52 | { 53 | prefactor = 0.001; // Convert T to mT 54 | type = zeeman; 55 | field = "0.0 0.035355339 0.035355339 "; 56 | spins = RPElectron1,RPElectron2; 57 | } 58 | 59 | // --------------------------------------------------------- 60 | // Spin States 61 | // --------------------------------------------------------- 62 | State Singlet // |S> 63 | { 64 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> - |-1/2,1/2>; 65 | } 66 | 67 | State T0 // |T0> 68 | { 69 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> + |-1/2,1/2>; 70 | } 71 | 72 | State Tp // |T+> 73 | { 74 | spin(RPElectron2) = |1/2>; 75 | spin(RPElectron1) = |1/2>; 76 | } 77 | 78 | State Tm // |T-> 79 | { 80 | spin(RPElectron2) = |-1/2>; 81 | spin(RPElectron1) = |-1/2>; 82 | } 83 | 84 | State Identity // Identity projection 85 | { 86 | } 87 | 88 | // --------------------------------------------------------- 89 | // SpinSystem Properties 90 | // --------------------------------------------------------- 91 | Properties properties 92 | { 93 | Initialstate = Singlet; 94 | } 95 | } 96 | // ------------------------------------------------------------- 97 | Settings 98 | { 99 | Settings general 100 | { 101 | steps = 1; //88; 102 | notifications = details; 103 | } 104 | 105 | } 106 | // ------------------------------------------------------------- 107 | Run 108 | { 109 | Task Method1 110 | { 111 | type = redfield-relaxation-timeevolution; 112 | logfile = "redfield-relaxation-timeevolution.log"; 113 | datafile = "redfield-relaxation-timeevolution.dat"; 114 | Timestep = 0.01; 115 | TotalTime = 1000; 116 | 117 | } 118 | 119 | } 120 | 121 | -------------------------------------------------------------------------------- /SpinAPI/Trajectory.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // Trajectory class (SpinAPI Module) 3 | // ------------------ 4 | // A general trajectory class used to load all kinds of trajectories. 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // (c) 2025 Quantum Biology and Computational Physics Group. 8 | // See LICENSE.txt for license information. 9 | ///////////////////////////////////////////////////////////////////////// 10 | #ifndef MOD_SpinAPI_Trajectory 11 | #define MOD_SpinAPI_Trajectory 12 | 13 | #include 14 | #include 15 | 16 | namespace SpinAPI 17 | { 18 | class Trajectory 19 | { 20 | private: 21 | // Implementation details 22 | std::string filename; 23 | std::map headers; 24 | std::vector> data; 25 | 26 | // Private character validation methods 27 | bool isAlphanumericCharacter(const char &) const; 28 | bool isNumericCharacter(const char &) const; 29 | bool isDelimiter(const char &) const; 30 | 31 | void AddNumber(unsigned int, std::string); // Puts a number into the next column of the row, provided there are enough headers 32 | void SetHeader(unsigned int, std::string); 33 | 34 | public: 35 | // Constructors / Destructors 36 | Trajectory(); 37 | Trajectory(const Trajectory &); // Copy-constructor 38 | ~Trajectory(); 39 | 40 | // Operators 41 | const Trajectory &operator=(const Trajectory &); // Copy-assignment 42 | 43 | // Public methods 44 | bool Load(const std::string &); // Loads the given trajectory file 45 | bool Clear(); // Removes any loaded trajectory data 46 | 47 | // TODO: Consider using size_t or vector::size_type instead of unsigned int 48 | // Note that row and column numbers are zero-based 49 | // Get methods return zero if the row or column does not exist 50 | double Get(const unsigned int _row, const unsigned int _column) const; 51 | double Get(const unsigned int _row, const std::string &_column) const; 52 | double Get(const int _row, const int _column) const; 53 | double Get(const int _row, const std::string &_column) const; 54 | 55 | bool HasColumn(std::string _header) const; 56 | bool HasColumn(std::string _header, unsigned int &_headerColumn) const; 57 | 58 | // Sets the uint& to the first row that is equal or greater/less than the given value, 59 | // and sets the double& to the value found in that row 60 | // Returns false if not value was found satifying the constraint (greater/less than) 61 | bool FirstRowEqGreaterThan(double _value, unsigned int _column, unsigned int &_row, double &_firstGreaterValue) const; 62 | bool FirstRowEqGreaterThan(double _value, std::string _column, unsigned int &_row, double &_firstGreaterValue) const; 63 | bool FirstRowEqLessThan(double _value, unsigned int _column, unsigned int &_row, double &_firstLessValue) const; 64 | bool FirstRowEqLessThan(double _value, std::string _column, unsigned int &_row, double &_firstLessValue) const; 65 | 66 | unsigned int Length() const; // Returns number of rows 67 | }; 68 | 69 | // Non-member non-friend functions 70 | } 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /RunSection/ActionTarget.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ActionTarget (RunSection module) 3 | // ------------------ 4 | // A class template describing a target for Action objects to act on. 5 | // 6 | // Defines ActionScalar (double) and ActionVector (arma::vec). 7 | // 8 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 9 | // (c) 2025 Quantum Biology and Computational Physics Group. 10 | // See LICENSE.txt for license information. 11 | ///////////////////////////////////////////////////////////////////////// 12 | #ifndef MOD_RunSection_ActionTarget 13 | #define MOD_RunSection_ActionTarget 14 | 15 | #include 16 | 17 | namespace RunSection 18 | { 19 | template 20 | using CheckFunction = bool (*)(const T &); 21 | 22 | template 23 | class ActionTarget 24 | { 25 | private: 26 | // Data reference to act on 27 | T *data; 28 | 29 | // Other data members 30 | bool readonly; 31 | T initialValue; 32 | 33 | // Function pointers 34 | bool (*check)(const T &); 35 | 36 | public: 37 | // Constructors / Destructors 38 | ActionTarget(T &_data, CheckFunction _check, bool _readonly = false) : data(&_data), readonly(_readonly), initialValue(_data), check(_check){}; // Normal constructor 39 | ActionTarget(const ActionTarget &_at) : data(_at.data), readonly(_at.readonly), initialValue(_at.initialValue), check(_at.check){}; // Copy-constructor 40 | ~ActionTarget(){}; // Destructor 41 | 42 | // Operators 43 | ActionTarget &operator=(const ActionTarget &_at) // Copy-assignment 44 | { 45 | this->data = _at.data; 46 | this->readonly = _at.readonly; 47 | this->initialValue = _at.initialValue; 48 | this->check = _at.check; 49 | 50 | return (*this); 51 | } 52 | 53 | // Get the value 54 | // It is guaranteed to be different from nullptr since a reference was passed to the constructor (or to the constructor of the object used to copy construct/assign) 55 | T Get() const 56 | { 57 | return (*data); 58 | } 59 | 60 | // Set the value, if not a readonly ActionTarget 61 | // If a check-function was provided, use it to verify the input 62 | bool Set(const T &_in) 63 | { 64 | if (this->readonly || (this->check != nullptr && this->check(_in) == false)) 65 | return false; 66 | 67 | *(this->data) = _in; 68 | return true; 69 | } 70 | 71 | // Readonly ActionTargets does not have a Set method, but can be changed in other ways (i.e. the prefactor in an Interaction object may be changed by a trajectory) 72 | // Such changes in readonly-ActionTargets can be reversed to an initial value through this method. 73 | void Reset() 74 | { 75 | *(this->data) = this->initialValue; 76 | } 77 | 78 | // Other public methods 79 | bool HasCheck() const { return (this->check != nullptr); }; 80 | bool IsReadonly() const { return this->readonly; } 81 | }; 82 | 83 | using ActionScalar = ActionTarget; 84 | using NamedActionScalar = std::pair; 85 | 86 | using ActionVector = ActionTarget; 87 | using NamedActionVector = std::pair; 88 | } 89 | 90 | #endif 91 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskStaticSSPowderSpectra.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskStaticSSPowderSpectra (RunSection module) developed by Irina Anisimova. 3 | // ------------------ 4 | // 5 | // Simple quantum yield calculation in Liouville space, derived from the 6 | // properties of the Laplace transformation. 7 | // 8 | // Molecular Spin Dynamics Software. 9 | // (c) 2022 Quantum Biology and Computational Physics Group. 10 | // See LICENSE.txt for license information. 11 | ///////////////////////////////////////////////////////////////////////// 12 | #ifndef MOD_RunSection_TaskStaticSSPowderSpectra 13 | #define MOD_RunSection_TaskStaticSSPowderSpectra 14 | 15 | #include "BasicTask.h" 16 | #include "SpinAPIDefines.h" 17 | #include "SpinSpace.h" 18 | #include "Utility.h" 19 | 20 | namespace RunSection 21 | { 22 | //Because the declaration of i is long define it as a new variable that is easier to use 23 | using SystemIterator = std::vector::const_iterator; 24 | 25 | class TaskStaticSSPowderSpectra : public BasicTask 26 | { 27 | private: 28 | double timestep; 29 | double totaltime; 30 | SpinAPI::ReactionOperatorType reactionOperators; 31 | 32 | void WriteHeader(std::ostream &); // Write header for the output file 33 | static arma::cx_vec ComputeRhoDot(double t, arma::sp_cx_mat& L, arma::cx_vec& K, arma::cx_vec RhoNaught); 34 | bool ProjectAndPrintOutputLine(auto &_i, SpinAPI::SpinSpace &_space, arma::cx_vec &_rhovec, double &_printedtime, double _timestep, unsigned int &_n, bool &_cidsp, std::ostream &_datastream, std::ostream &_logstream); 35 | bool ProjectAndPrintOutputLine(auto &_i, SpinAPI::SpinSpace &_space, arma::cx_vec &_rhovec, arma::sp_cx_mat &_eigen_vec, double &_printedtime, double _timestep, unsigned int &_n, bool &_cidsp, std::ostream &_datastream, std::ostream &_logstream); 36 | bool ProjectAndPrintOutputLineInf(auto &_i, SpinAPI::SpinSpace &_space, arma::cx_vec &_rhovec, double &_printedtime, double _timestep, bool &_cidsp, std::ostream &_datastream, std::ostream &_logstream); 37 | bool ProjectAndPrintOutputLineInf(auto &_i, SpinAPI::SpinSpace &_space, arma::cx_vec &_rhovec, arma::sp_cx_mat &_eigen_vec, double &_printedtime, double _timestep, bool &_cidsp, std::ostream &_datastream, std::ostream &_logstream); 38 | 39 | 40 | protected: 41 | bool RunLocal() override; 42 | bool Validate() override; 43 | 44 | public: 45 | // Constructors / Destructors 46 | TaskStaticSSPowderSpectra(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 47 | ~TaskStaticSSPowderSpectra(); // Destructor 48 | 49 | bool GetEigenvectors_H0(SpinAPI::SpinSpace &_space, arma::vec &_eigen_val, arma::sp_cx_mat &_eigen_vec_sp) const; 50 | bool GetEigenvectors_H0_Thermal(SpinAPI::SpinSpace &_space, std::vector &_thermalhamiltonian_list, arma::vec &_eigen_val, arma::sp_cx_mat &_eigen_vec_sp) const; 51 | bool CreateRotationMatrix(double &_alpha, double &_beta, double &_gamma, arma::mat &_R) const; 52 | bool CreateUniformGrid(int &_Npoints, std::vector> &_uniformGrid) const; 53 | bool CreateCustomGrid(int &_Npoints, std::vector> &_Grid) const; 54 | 55 | }; 56 | 57 | } 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /SpinAPI/SubSystem.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // SubSystem class (SpinAPI Module) 3 | // ------------------ 4 | // TODO: Write a description of the SubSystem class 5 | // 6 | // 7 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 8 | // (c) 2025 Quantum Biology and Computational Physics Group. 9 | // See LICENSE.txt for license information. 10 | ///////////////////////////////////////////////////////////////////////// 11 | #ifndef MOD_SpinAPI_SubSystem 12 | #define MOD_SpinAPI_SubSystem 13 | 14 | #include 15 | #include "MSDParserfwd.h" 16 | #include "SpinAPIfwd.h" 17 | 18 | //need to do 19 | //function to create livioullan superoperator for a given SpinSpace made up of multiple SubSystems - not done 20 | //function to create initial state for a given SpinSpace made up of multiple SubSystems - not done 21 | 22 | namespace SpinAPI 23 | { 24 | class SubSystem 25 | { 26 | public: 27 | struct Transition 28 | { 29 | std::shared_ptr TransitionObject; 30 | int type; // 0 transtion out of the system, 1 transiton into a other system, -1 unknown; 31 | std::string name; 32 | 33 | std::string source; 34 | std::string target; 35 | 36 | Transition(std::shared_ptr t, std::string n) 37 | : TransitionObject(t), type(-1), name(n), source(""), target("") 38 | { 39 | } 40 | }; 41 | 42 | private: 43 | // Implementation details 44 | std::string m_name; 45 | system_ptr m_system; 46 | std::vector> m_spins; 47 | std::vector> m_interactions; 48 | std::vector m_transtions; 49 | std::vector> m_operators; 50 | std::vector> m_pulses; 51 | 52 | std::shared_ptr m_properties; 53 | 54 | public: 55 | SubSystem(std::string, std::string, system_ptr); // Normal constructor 56 | // SubSystem(const SubSystem& ) = delete;//Copy constructor 57 | ~SubSystem(); // Destructor 58 | 59 | // Operator overloading 60 | const SubSystem &operator=(const SubSystem &) = delete; // Copy Assignment 61 | 62 | std::string Name() const; 63 | bool Validate(); // validates all the objects asssinged to the subsystem exist 64 | 65 | // Allow access to custom properties to be used for custom tasks 66 | // std::shared_ptr Properties() const; 67 | 68 | inline std::vector GetTransitions() 69 | { 70 | return m_transtions; 71 | } 72 | 73 | inline std::vector &GetTransitions_Ref() 74 | { 75 | return m_transtions; 76 | } 77 | 78 | std::vector GetInteractions(); 79 | 80 | void ModifyTransitionVec(int index, Transition NewTransition) 81 | { 82 | m_transtions[index] = NewTransition; 83 | } 84 | 85 | std::vector GetSpinNames(); 86 | }; 87 | 88 | using subsystem_ptr = std::shared_ptr; 89 | 90 | bool LinkTransitions(system_ptr); 91 | } 92 | 93 | #endif -------------------------------------------------------------------------------- /Example/magnetoreception/timeevolution/example_2_1_ns.msd: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------- 2 | // Simple time-evolution calculation on a radical pair. 3 | // Contains the N5 nucleus on FAD. May apply an oscillating magnetic field. 4 | // ------------------------------------------------------------- 5 | SpinSystem RPSystem 6 | { 7 | 8 | // --------------------------------------------------------- 9 | // Spins 10 | // --------------------------------------------------------- 11 | 12 | Spin FADN5 13 | { 14 | // Hyperfine tensor from: 15 | // "The quantum needle of the avian magnetic compass." 16 | // H. G. Hiscock et al. PNAS, 113, 4634-4639 (2016) 17 | tensor = matrix("-0.0989 0.0039 0.0;0.0039 -0.0881 0.0;0.0 0.0 1.7569"); 18 | spin = 1; 19 | } 20 | 21 | Spin RPElectron1 22 | { 23 | type = electron; 24 | tensor = isotropic(2); 25 | spin = 1/2; 26 | } 27 | 28 | Spin RPElectron2 29 | { 30 | type = electron; 31 | tensor = isotropic(2); 32 | spin = 1/2; 33 | } 34 | 35 | // --------------------------------------------------------- 36 | // Interactions 37 | // --------------------------------------------------------- 38 | Interaction radical1hyperfine 39 | { 40 | prefactor = 0.001; // Convert T to mT 41 | type = hyperfine; 42 | group1 = RPElectron1; 43 | group2 = FADN5; 44 | tensor = isotropic(1); 45 | tau_c = 1; 46 | g = 1; 47 | ops = 0; 48 | coeff = 1; 49 | } 50 | 51 | Interaction zeeman1 52 | { 53 | prefactor = 0.001; // Convert T to mT 54 | type = zeeman; 55 | field = "0.0 0.035355339 0.035355339 "; 56 | spins = RPElectron1,RPElectron2; 57 | } 58 | 59 | // --------------------------------------------------------- 60 | // Spin States 61 | // --------------------------------------------------------- 62 | State Singlet // |S> 63 | { 64 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> - |-1/2,1/2>; 65 | } 66 | 67 | State T0 // |T0> 68 | { 69 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> + |-1/2,1/2>; 70 | } 71 | 72 | State Tp // |T+> 73 | { 74 | spin(RPElectron2) = |1/2>; 75 | spin(RPElectron1) = |1/2>; 76 | } 77 | 78 | State Tm // |T-> 79 | { 80 | spin(RPElectron2) = |-1/2>; 81 | spin(RPElectron1) = |-1/2>; 82 | } 83 | 84 | State Identity // Identity projection 85 | { 86 | } 87 | 88 | // --------------------------------------------------------- 89 | // SpinSystem Properties 90 | // --------------------------------------------------------- 91 | Properties properties 92 | { 93 | Initialstate = Singlet; 94 | } 95 | } 96 | // ------------------------------------------------------------- 97 | Settings 98 | { 99 | Settings general 100 | { 101 | steps = 1; //88; 102 | notifications = details; 103 | } 104 | 105 | } 106 | // ------------------------------------------------------------- 107 | Run 108 | { 109 | Task Method1 110 | { 111 | type = redfield-relaxation-timeevolution; 112 | logfile = "redfield-relaxation-timeevolution.log"; 113 | datafile = "redfield-relaxation-timeevolution.dat"; 114 | Timestep = 0.1; 115 | TotalTime = 1000; 116 | 117 | } 118 | 119 | Task Method2 120 | { 121 | type = "staticss-timeevolution"; 122 | logfile = "example_timeevolution.log"; 123 | datafile = "example_timeevolution.dat"; 124 | Timestep = 0.1; 125 | TotalTime = 1000; 126 | 127 | } 128 | 129 | } 130 | 131 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Welcome to Molspin, the virtual spin dynamics laboratory! 2 | 3 | For more information about MolSpin and its features, we refer the reader to the official website: 4 | 5 | https://molspin.eu/ 6 | 7 | NOTE THAT THIS REPOSITORY IS IN ACTIVE DEVELOPMENT! PRODUCTION VERSIONS ARE AVAILABLE AT THE MOLSPIN WEBSITE! 8 | 9 | Join the Discord server: 10 | 11 | https://discord.gg/KXNKPBgchM 12 | 13 | PLEASE CITE THE FOLLOWING PAPER WHEN USING MOLSPIN. 14 | 15 | 16 | 17 | 25 | 26 |
18 |

19 | 20 | Spin Dynamics of Radical Pairs Using the Stochastic Schrödinger Equation in MolSpin 21 |
22 | Gediminas Jurgis Pazera, Thomas P. Fay, Ilia A. Solov’yov, P. J. Hore, Luca Gerhards, Journal of Chemical Theory and Computation 20, 19, 8412–8421, (2024) 23 |

24 |
27 | 28 | 29 | 30 | 38 | 39 |
31 |

32 | 33 | Modeling spin relaxation in complex radical systems using MolSpin 34 |
35 | Luca Gerhards, Claus Nielsen, Daniel R. Kattnig, P. J. Hore, Ilia A. Solov'yov, Journal of Computational Chemistry 1, (2023) 36 |

37 |
40 | 41 | 42 | 43 | 44 | 52 | 53 |
45 |

46 | 47 | MolSpin - Flexible and extensible general spin dynamics software 48 |
49 | Claus Nielsen, Ilia A. Solov'yov, Journal of Physical Chemistry 151, 194105, (2019) 50 |

51 |
54 | 55 | 56 | 57 | LICENCE: 58 | 59 | Developed by Claus Nielsen and Luca Gerhards at the Quantum Biology and Computational Physics Group (copyright 2025). 60 | 61 | MolSpin runs under the BSD 3-Clause License with an additional requirement for acknowledgment of specific publications. 62 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 63 | 64 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 65 | 66 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 67 | 68 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 69 | 70 | 4. Every use of the source code or binary form of the software should acknowledge ALL the MolSpin publications. 71 | 72 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 73 | -------------------------------------------------------------------------------- /.github/workflows/docker-build-env.yml: -------------------------------------------------------------------------------- 1 | # 2 | name: Create and publish docker build environment 3 | 4 | # Configures this workflow to run every time a change is pushed to the branch called `release`. 5 | on: 6 | push: 7 | branches: ['dockerenv'] 8 | 9 | # Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. 10 | env: 11 | REGISTRY: ghcr.io 12 | IMAGE_NAME: ${{ github.repository_owner }}/molspin-build-env 13 | 14 | # There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. 15 | jobs: 16 | build-and-push-image: 17 | runs-on: ubuntu-latest 18 | # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. 19 | permissions: 20 | contents: read 21 | packages: write 22 | attestations: write 23 | id-token: write 24 | # 25 | steps: 26 | - name: Checkout repository 27 | uses: actions/checkout@v4 28 | # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. 29 | - name: Log in to the Container registry 30 | uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 31 | with: 32 | registry: ${{ env.REGISTRY }} 33 | username: ${{ github.actor }} 34 | password: ${{ secrets.GITHUB_TOKEN }} 35 | # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. 36 | - name: Extract metadata (tags, labels) for Docker 37 | id: meta 38 | uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 39 | with: 40 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} 41 | # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. 42 | # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository. 43 | # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. 44 | - name: Build and push Docker image 45 | id: push 46 | uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 47 | with: 48 | context: . 49 | target: build-env 50 | push: true 51 | tags: ${{ steps.meta.outputs.tags }} 52 | labels: ${{ steps.meta.outputs.labels }} 53 | 54 | # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds). 55 | - name: Generate artifact attestation 56 | uses: actions/attest-build-provenance@v2 57 | with: 58 | subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} 59 | subject-digest: ${{ steps.push.outputs.digest }} 60 | push-to-registry: true -------------------------------------------------------------------------------- /.github/workflows/docker-molspin.yml: -------------------------------------------------------------------------------- 1 | # 2 | name: Create and publish molspin docker container 3 | 4 | # Configures this workflow to run every time a change is pushed to the branch called `release`. 5 | on: 6 | release: 7 | types: [published] 8 | push: 9 | branches: [ "main" ] 10 | 11 | # Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds. 12 | env: 13 | REGISTRY: ghcr.io 14 | IMAGE_NAME: ${{ github.repository }} 15 | 16 | # There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu. 17 | jobs: 18 | build-and-push-image: 19 | runs-on: ubuntu-latest 20 | # Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job. 21 | permissions: 22 | contents: read 23 | packages: write 24 | attestations: write 25 | id-token: write 26 | # 27 | steps: 28 | - name: Checkout repository 29 | uses: actions/checkout@v4 30 | # Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here. 31 | - name: Log in to the Container registry 32 | uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1 33 | with: 34 | registry: ${{ env.REGISTRY }} 35 | username: ${{ github.actor }} 36 | password: ${{ secrets.GITHUB_TOKEN }} 37 | # This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels. 38 | - name: Extract metadata (tags, labels) for Docker 39 | id: meta 40 | uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 41 | with: 42 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} 43 | # This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages. 44 | # It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository. 45 | # It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step. 46 | - name: Build and push Docker image 47 | id: push 48 | uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 49 | with: 50 | context: . 51 | push: true 52 | tags: ${{ steps.meta.outputs.tags }} 53 | labels: ${{ steps.meta.outputs.labels }} 54 | 55 | # This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds). 56 | - name: Generate artifact attestation 57 | uses: actions/attest-build-provenance@v2 58 | with: 59 | subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}} 60 | subject-digest: ${{ steps.push.outputs.digest }} 61 | push-to-registry: true 62 | 63 | -------------------------------------------------------------------------------- /MSDParser/FileReader.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // FileReader class (MSDParser Module) 3 | // ------------------ 4 | // Reads files and passes the read objects on to the MSDParser. 5 | // 6 | // Any errors in reading the files will be handled by the FileReader, 7 | // and if the file could not be found/opened, an object with 8 | // ObjectType::EOF will be returned by ReadObject() and an error message 9 | // will be written by FileReader. 10 | // 11 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 12 | // (c) 2025 Quantum Biology and Computational Physics Group. 13 | // See LICENSE.txt for license information. 14 | ///////////////////////////////////////////////////////////////////////// 15 | #ifndef MOD_MSDParser_FileReader 16 | #define MOD_MSDParser_FileReader 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "MSDParserDefines.h" 23 | 24 | namespace MSDParser 25 | { 26 | class FileReader 27 | { 28 | private: 29 | // Static list of read files to avoid circular includes 30 | static std::vector filelist; 31 | static std::map define_directives; 32 | 33 | // Static methods 34 | static std::string PathFromFileName(const std::string &); 35 | static bool PathIsAbsolute(const std::string &); 36 | 37 | // Implementation details 38 | ObjectGroup objectGroupType; 39 | std::string objectGroupName; 40 | std::shared_ptr subfile; 41 | std::ifstream filehandle; // Initialized in constructor 42 | std::string filename; // Used when reporting errors 43 | int linenumber; // Keeps track of linenumber in the file held by the FileReader (used to report parsing errors) 44 | bool inObjectGroup; // Whether or not the FileReader file pointer is inside an ObjectGroup 45 | bool inExcludedDirective; // Whether or not the FileReader file pointer is inside an "ifdef", "ifndef" or "else" directive that should be skipped (e.g. "ifdef" not satisfied) 46 | 47 | // Private methods to validate read characters 48 | bool isAlphanumericCharacter(const char &) const; 49 | bool isAllowedCharacter(const char &) const; 50 | bool isAllowedCharacterInString(const char &) const; 51 | char getLowerCase(const char &) const; // Converts uppercase letters to lowercase, works similar to isAlphanumericCharacter 52 | 53 | // Private method to handle '#'-directives read from the input file 54 | void handleDirective(const std::string &, const std::string &, const std::string &); 55 | 56 | // Private method to set the current object group 57 | void setObjectGroup(const std::string &, const std::string &); 58 | 59 | // Private method to create an object, once enough data is read 60 | MSDFileObject createObject(const std::string &, const std::string &, std::string); 61 | 62 | public: 63 | // Constructors / Destructors 64 | explicit FileReader(const std::string &); // Normal constructor 65 | FileReader(const FileReader &) = delete; // Do not allow use of the copy constructor 66 | ~FileReader(); // Destructor 67 | 68 | // Operators 69 | FileReader &operator=(const FileReader &) = delete; // Do not allow use of copy-assignment 70 | 71 | // Public methods 72 | bool IsOpen(); // Checks whether the requested file was opened properly 73 | MSDFileObject ReadObject(); 74 | ObjectGroup ObjectGroupType() const { return this->objectGroupType; }; 75 | std::string ObjectGroupName() const { return this->objectGroupName; }; 76 | 77 | // Static methods 78 | static std::vector GetFileList(); 79 | static std::map GetDefinitions(); 80 | static bool AddDefinition(const std::string &, const std::string &_value = ""); 81 | }; 82 | } 83 | 84 | #endif -------------------------------------------------------------------------------- /SpinAPI/SpinAPIDefines.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // Defines (SpinAPI Module) 3 | // ------------------ 4 | // Definitions used by the SpinAPI Module. 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // (c) 2025 Quantum Biology and Computational Physics Group. 8 | // See LICENSE.txt for license information. 9 | ///////////////////////////////////////////////////////////////////////// 10 | #ifndef MOD_SpinAPI_Defines 11 | #define MOD_SpinAPI_Defines 12 | 13 | namespace SpinAPI 14 | { 15 | // Used by the Spin class 16 | enum class SpinType 17 | { 18 | Electron, 19 | Nucleus, 20 | NotSpecified, 21 | }; 22 | 23 | // Used by the Trajectory class 24 | enum class InterpolationType 25 | { 26 | Stepwise, // Stepwise constant function 27 | Linear, // Linear interpolation 28 | }; 29 | 30 | // Used by the Interaction class 31 | enum class InteractionType 32 | { 33 | Undefined, 34 | SingleSpin, 35 | DoubleSpin, 36 | Exchange, 37 | Zfs, 38 | SemiClassicalField 39 | }; 40 | 41 | // Used by the Interaction class to determine the time-dependence of the field for SingleSpin interactions 42 | enum class InteractionFieldType 43 | { 44 | Static, 45 | LinearPolarization, // Monochromatic linearly polarized radiation, parameters: "frequency", "phase" 46 | CircularPolarization, // Monochromatic circularly polarized radiation, parameters: "frequency", "phase", "axis" 47 | Broadband, // Broadband noise, parameters: "minfreq", "maxfreq", "stdev", "components", "randomorientations" 48 | OUGeneral, // Ornstein-Uhlenbeck noise, parameters: "correlationtime", "stdev", "timestep", "randomorientations" 49 | Trajectory, // Time-dependence is given by a trajectory 50 | }; 51 | 52 | // Used by the Interaction class to determine the time-dependence of the tensor for DoubleSpin interactions 53 | enum class InteractionTensorType 54 | { 55 | Static, 56 | Monochromatic, // Monochromatic noise, parameters: "frequency", "phase", "amplitude" 57 | Broadband, // Broaband noise, parameters: "minfreq", "maxfreq", "stdev", "components" 58 | OUGeneral, // Ornstein-Uhlenbeck noise, parameters: "correlationtime", "stdev", "timestep" 59 | Trajectory, // Time-dependence is given by a trajectory 60 | }; 61 | 62 | // Used by the Transition class 63 | enum class TransitionType 64 | { 65 | Source, 66 | Sink, 67 | }; 68 | 69 | // The types of supported reaction operators 70 | enum class ReactionOperatorType 71 | { 72 | Unspecified, // Used by the transition class - SpinAPI::SpinSpace will use the reaction operator type assigned to it if a transition has an unspecified reaction operator type 73 | Haberkorn, 74 | Lindblad, 75 | }; 76 | 77 | // The types of special operators defined in SpinAPI::Operator objects 78 | enum class OperatorType 79 | { 80 | Unspecified, 81 | RelaxationLindblad, // Single-spin operator, i.e. uses Sx, Sy and Sz operators of the specified spins 82 | RelaxationLindbladDoubleSpin, 83 | RelaxationDephasing, 84 | RelaxationRandomFields, 85 | RelaxationT1, 86 | RelaxationT2, 87 | }; 88 | 89 | // The types of special operators defined in SpinAPI::Operator objects 90 | enum class PulseType 91 | { 92 | Unspecified, 93 | InstantPulse, 94 | LongPulse, 95 | LongPulseStaticField, 96 | MWPulse, 97 | ShapedPulse, 98 | }; 99 | 100 | // Types of standard outputs based on ActionTargets, to be used to by the StandardOutput class 101 | enum class StandardOutputType 102 | { 103 | VectorXYZ, 104 | VectorAngle, 105 | VectorLength, 106 | VectorDot, 107 | Scalar, 108 | Undefined, 109 | }; 110 | } 111 | 112 | #endif 113 | -------------------------------------------------------------------------------- /SpinAPI/Function.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // Function class (SpinAPI Module) 3 | // ------------------ 4 | // The Function class represents a mathmatical function. 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // (c) 2025 Quantum Biology and Computational Physics Group. 8 | // See LICENSE.txt for license information. 9 | ///////////////////////////////////////////////////////////////////////// 10 | #ifndef MOD_SpinAPI_Function 11 | #define MOD_SpinAPI_Function 12 | 13 | #include 14 | #include 15 | 16 | namespace SpinAPI 17 | { 18 | class Function // handles prefactors like cos and sin but essentially any other mathmatical function 19 | { 20 | public: 21 | typedef void *(*FuncPtr)(void *); 22 | 23 | enum class ReturnType 24 | { 25 | d = 0, // double 26 | cd, // complex double 27 | undefined 28 | }; 29 | 30 | enum class VarType 31 | { 32 | d = 0, // double 33 | z = 1, // complex 34 | f = 2 // function 35 | }; 36 | 37 | struct VariableDefinition 38 | { 39 | std::string name; 40 | VarType type; 41 | 42 | // only useful for cd and f types 43 | std::string VariableString = ""; 44 | std::vector InternalVariables = {}; 45 | 46 | // only useful for f types 47 | std::shared_ptr InternalFunction = nullptr; 48 | }; 49 | 50 | // depricated 51 | enum class InternalOperations 52 | { 53 | p = 0, // plus 54 | mi, // minus 55 | mu, // multiply 56 | d // divide 57 | }; 58 | 59 | private: 60 | std::string m_FunctionName; 61 | FuncPtr m_func; // function pointer 62 | ReturnType m_funcType; // function type 63 | std::vector m_variables; 64 | std::vector m_duplicates; 65 | std::string m_FunctionString; 66 | std::string m_PostFixEquation; 67 | 68 | // depricated 69 | std::vector m_factors; 70 | std::vector m_op; 71 | std::vector m_VarDepth; 72 | // std::vector m_variables; 73 | 74 | private: 75 | std::complex EvaluateFuncValue(std::vector); 76 | 77 | public: 78 | arma::cx_double operator()(void *value); // function evaluation for one variable 79 | arma::cx_double operator()(std::vector value); // multiple variables 80 | Function(FuncPtr, ReturnType, std::string, std::vector); 81 | Function(FuncPtr, ReturnType, std::string, VariableDefinition var = {"", VarType::d, "", {""}, nullptr}); 82 | 83 | std::vector GetVariable(); 84 | std::string GetName(); 85 | 86 | VariableDefinition FindVar(std::string); 87 | 88 | void SetFunctionString(std::string FuncString) 89 | { 90 | m_FunctionString = FuncString; 91 | } 92 | void SetPostFix(std::string PostFix) 93 | { 94 | m_PostFixEquation = PostFix; 95 | } 96 | std::string GetFunctionString() 97 | { 98 | return m_FunctionString; 99 | } 100 | std::string GetPostFixEq() 101 | { 102 | return m_PostFixEquation; 103 | } 104 | // using FunctionPtr = std::shared_ptr; 105 | }; 106 | 107 | std::shared_ptr FunctionParser(std::string &, std::string &, int FuncStartNum = 0, bool ResetComplexNum = false); // function name i.e sin and function contents i.e 0.5x 108 | 109 | namespace MathematicalFunctions 110 | { 111 | void *sin(void *); // double 112 | void *cos(void *); // double 113 | void *scalar(void * = nullptr); // double 114 | void *scalarcx(void * = nullptr); // complex double 115 | void *exp(void *); // double 116 | void *expcx(void *); // complex double 117 | } 118 | 119 | } 120 | 121 | #endif -------------------------------------------------------------------------------- /Example/performance_redfield/example_1.msd: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------- 2 | // MolSpin Input file example 3 | // See the user manual for more information 4 | // Find it at www.molspin.eu 5 | // ------------------------------------------------------------- 6 | SpinSystem system1 7 | { 8 | // --------------------------------------------------------- 9 | // Spins 10 | // --------------------------------------------------------- 11 | Spin RPElectron1 12 | { 13 | type = electron; 14 | spin = 1/2; 15 | tensor = isotropic(2.0023); 16 | } 17 | 18 | Spin RPElectron2 19 | { 20 | type = electron; 21 | spin = 1/2; 22 | tensor = isotropic(2.0023); 23 | } 24 | 25 | Spin H1 26 | { 27 | type = nucleus; 28 | spin = 1/2; 29 | } 30 | 31 | 32 | // ------------------------- 33 | // Zeeman interaction 34 | // ------------------------- 35 | 36 | Interaction zeeman1 37 | { 38 | type = zeeman; 39 | field = "0 0 50"; 40 | spins = RPElectron1; 41 | } 42 | 43 | Interaction zeeman2 44 | { 45 | type = zeeman; 46 | field = "0 0 50"; 47 | spins = RPElectron2; 48 | } 49 | 50 | // ------------------------- 51 | // Hyperfine interactions 52 | // ------------------------- 53 | Interaction radical1hyperfine 54 | { 55 | type = hyperfine; 56 | group1 = RPElectron1; 57 | group2 = H1; 58 | tensor = matrix("0.5 0.0 0.0;0.0 0.5 0.0;0.0 0.0 2.0"); 59 | tau_c = 0.0001; 60 | g = 1; 61 | } 62 | 63 | // ------------------------- 64 | // Spin States 65 | // --------------------------------------------------------- 66 | 67 | State Singlet // |S> 68 | { 69 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> - |-1/2,1/2>; 70 | } 71 | 72 | State T0 // |T0> 73 | { 74 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> + |-1/2,1/2>; 75 | } 76 | 77 | State Tp // |T+> 78 | { 79 | spin(RPElectron2) = |1/2>; 80 | spin(RPElectron1) = |1/2>; 81 | } 82 | 83 | State Tm // |T-> 84 | { 85 | spin(RPElectron2) = |-1/2>; 86 | spin(RPElectron1) = |-1/2>; 87 | } 88 | State Identity 89 | { 90 | } 91 | 92 | // --------------------------------------------------------- 93 | // Transitions 94 | // --------------------------------------------------------- 95 | Transition Product1 96 | { 97 | type = sink; 98 | source = Singlet; 99 | rate = 0.001; 100 | } 101 | 102 | Transition Product4 103 | { 104 | type = sink; 105 | source = T0; 106 | rate =0.001; 107 | } 108 | 109 | Transition Product5 110 | { 111 | type = sink; 112 | source = Tp; 113 | rate =0.001; 114 | } 115 | 116 | Transition Product6 117 | { 118 | type = sink; 119 | source = Tm; 120 | rate =0.001; 121 | } 122 | 123 | 124 | // ------------------------- 125 | // Spin system properties 126 | // ------------------------- 127 | Properties properties 128 | { 129 | initialstate = Singlet; 130 | } 131 | } 132 | // ------------------------------------------------------------- 133 | Settings 134 | { 135 | Settings general 136 | { 137 | steps = 1; //88; 138 | notifications = details; 139 | } 140 | 141 | } 142 | // ------------------------------------------------------------- 143 | Run 144 | { 145 | Task Method2 146 | { 147 | type = redfield-relaxation; 148 | logfile = "redfield-relaxation.log"; 149 | datafile = "redfield-relaxation.dat"; 150 | transitionyields = true; 151 | 152 | } 153 | 154 | } 155 | 156 | -------------------------------------------------------------------------------- /RunSection/Tasks/TaskMultiRadicalPairSSTimeEvo.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // TaskMultiRadicalPairSSTimeEvo (RunSection module) 3 | // ------------------ 4 | // 5 | // Simple time-evolution calculation in Liouville space. 6 | // 7 | // -- Multi-system version: Allows transitions between SpinSystems -- 8 | // 9 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 10 | // (c) 2025 Quantum Biology and Computational Physics Group. 11 | // See LICENSE.txt for license information. 12 | ///////////////////////////////////////////////////////////////////////// 13 | #ifndef MOD_RunSection_TaskMultiRadicalPairSSTimeEvo 14 | #define MOD_RunSection_TaskMultiRadicalPairSSTimeEvo 15 | 16 | #include "BasicTask.h" 17 | #include "SpinSpace.h" 18 | #include "SpinSystem.h" 19 | #include "SpinAPIDefines.h" 20 | #include "Utility.h" 21 | 22 | namespace RunSection 23 | { 24 | struct SubSystemTransition 25 | { 26 | SpinAPI::transition_ptr transition; 27 | int type; //0 = Transition out of one subsystem, 1 = Transition between two subsytems 28 | std::string source; 29 | std::string target; 30 | SubSystemTransition() 31 | :transition(nullptr), type(-1), source(""), target("") 32 | { 33 | } 34 | }; 35 | 36 | struct TrajectoryData 37 | { 38 | std::string subsystem; 39 | std::vector> StateTrace; 40 | 41 | TrajectoryData(std::string name) 42 | :subsystem(name) 43 | { 44 | StateTrace = {}; 45 | } 46 | }; 47 | 48 | class TaskMultiRadicalPairSSTimeEvo : public BasicTask 49 | { 50 | private: 51 | double timestep; 52 | double OriginalTimestep; 53 | double totaltime; 54 | SpinAPI::ReactionOperatorType reactionOperators; 55 | 56 | void WriteHeader(std::ostream &, bool yield = true); // Write header for the output file 57 | 58 | // Private method that gathers and outputs the results from a given time-integrated density operator 59 | void GatherResults(const arma::cx_mat &, const SpinAPI::SpinSystem &, const SpinAPI::SpinSpace &, std::vector>& traj); 60 | 61 | std::vector EvaluateYield(const std::vector>>& trajectory, const SpinAPI::system_ptr&SpinSpace, const std::vector>>& SubSystemSpins, const std::vector& SubSystemsTransitions); 62 | void StateYield(double, double&, const std::vector>&, std::vector& ); //Method that calculates the yeild for a given state 63 | void StateYield(double, double&, int, int, arma::cx_mat&, arma::cx_vec&); //rate, yield (to be retunred), spinsystem, projection operator, state density vec 64 | double simpson_integration(std::vector x_list, std::vector y_list); 65 | 66 | bool GenerateHamiltonian(const std::vector interactions, arma::sp_cx_mat& H, int dimension, std::shared_ptr SpinSystem); 67 | bool GenerateReactionOperator(const std::vector transitions, arma::sp_cx_mat& K, int dimension, std::shared_ptr SpinSystem, std::string source); 68 | 69 | bool ValidateSubSystems(); 70 | 71 | //RungeKutta4 method 72 | //bool RungeKutta4(arma::sp_cx_mat& L, arma::cx_vec& RhoNaught, arma::cx_vec& drhodt, double timestep); 73 | //static Matrix ComputeRhoDot(Matrix& L, Matrix& K, Matrix RhoNaugt); //k in this case isn't refering to the reaction operator K but k_i, i E {1,2,3,4} for the RK4 method 74 | static arma::cx_vec ComputeRhoDot(double t, arma::sp_cx_mat& L, arma::cx_vec& K, arma::cx_vec RhoNaught); 75 | 76 | bool CalcYieldOnly(arma::sp_cx_mat& L, arma::cx_vec& RhoNaught, arma::cx_vec& ReturnVec); //L matrix, RhoNaught and a vector to return the data 77 | 78 | protected: 79 | bool RunLocal() override; 80 | bool Validate() override; 81 | 82 | public: 83 | // Constructors / Destructors 84 | TaskMultiRadicalPairSSTimeEvo(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 85 | ~TaskMultiRadicalPairSSTimeEvo(); // Destructor 86 | }; 87 | } 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /RunSection/Actions/ActionAddVector.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ActionAddVector implementation (RunSection module) 3 | // 4 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 5 | // (c) 2025 Quantum Biology and Computational Physics Group. 6 | // See LICENSE.txt for license information. 7 | ///////////////////////////////////////////////////////////////////////// 8 | #include "ActionAddVector.h" 9 | #include "ObjectParser.h" 10 | 11 | namespace RunSection 12 | { 13 | // ----------------------------------------------------- 14 | // ActionAddVector Constructors and Destructor 15 | // ----------------------------------------------------- 16 | ActionAddVector::ActionAddVector(const MSDParser::ObjectParser &_parser, const std::map &_scalars, const std::map &_vectors) : Action(_parser, _scalars, _vectors), actionVector(nullptr), direction() 17 | { 18 | } 19 | 20 | ActionAddVector::~ActionAddVector() 21 | { 22 | } 23 | // ----------------------------------------------------- 24 | // ActionAddVector derived methods 25 | // ----------------------------------------------------- 26 | // Method to perform a step 27 | bool ActionAddVector::DoStep() 28 | { 29 | // Make sure we have an ActionVector to act on 30 | if (actionVector == nullptr || !this->IsValid()) 31 | { 32 | return false; 33 | } 34 | 35 | // Retrieve the vector we want to change 36 | arma::vec vec = actionVector->Get(); 37 | 38 | // Add a vector to the ActionVector 39 | vec += this->Value() * this->direction; 40 | 41 | // Set the new vector 42 | return this->actionVector->Set(vec); 43 | } 44 | 45 | // Method to prepare the action and check whether it is valid 46 | bool ActionAddVector::DoValidate() 47 | { 48 | // Make sure that a direction is specified 49 | arma::vec tmp; 50 | if (!this->Properties()->Get("direction", tmp)) 51 | { 52 | std::cout << "ERROR: No direction specified for the AddVector action \"" << this->Name() << "\"!" << std::endl; 53 | return false; 54 | } 55 | 56 | // Attemp to set the direction 57 | if (!this->SetDirection(tmp)) 58 | { 59 | std::cout << "ERROR: Invalid direction specified for the AddVector action \"" << this->Name() << "\"!" << std::endl; 60 | return false; 61 | } 62 | 63 | // Get the ActionVector name 64 | std::string str; 65 | if (!this->Properties()->Get("actionvector", str) && !this->Properties()->Get("vector", str)) 66 | { 67 | std::cout << "ERROR: No ActionVector specified for the AddVector action \"" << this->Name() << "\"!" << std::endl; 68 | return false; 69 | } 70 | 71 | // Attemp to set the ActionVector 72 | if (!this->Vector(str, &(this->actionVector))) 73 | { 74 | std::cout << "ERROR: Could not find ActionVector \"" << str << "\" specified for the AddVector action \"" << this->Name() << "\"!" << std::endl; 75 | return false; 76 | } 77 | 78 | // Readonly ActionTargets cannot be acted on 79 | if (this->actionVector->IsReadonly()) 80 | { 81 | std::cout << "ERROR: Readonly ActionVector \"" << str << "\" specified for the AddVector action \"" << this->Name() << "\"! Cannot act on this vector!" << std::endl; 82 | return false; 83 | } 84 | 85 | return true; 86 | } 87 | // ----------------------------------------------------- 88 | // ActionAddVector private methods 89 | // ----------------------------------------------------- 90 | // Sets the direction unit vector 91 | bool ActionAddVector::SetDirection(const arma::vec &_vec) 92 | { 93 | // Check whether we have a valid direction vector 94 | if (_vec.n_elem == 3 && _vec.is_finite()) 95 | { 96 | // Set the direction, and normalize it (the length is set by "value" on the action) 97 | this->direction = normalise(_vec); 98 | 99 | return true; 100 | } 101 | 102 | return false; 103 | } 104 | 105 | bool ActionAddVector::Reset() 106 | { 107 | this->actionVector->Reset(); 108 | return true; 109 | } 110 | // ----------------------------------------------------- 111 | } 112 | -------------------------------------------------------------------------------- /RunSection/Actions/ActionLogSpace.cpp: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // ActionLogSpace implementation (RunSection module) 3 | // 4 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 5 | // (c) 2025 Quantum Biology and Computational Physics Group. 6 | // See LICENSE.txt for license information. 7 | ///////////////////////////////////////////////////////////////////////// 8 | #include "ActionLogSpace.h" 9 | #include "ObjectParser.h" 10 | 11 | bool RunSection::ActionLogSpace::CalculatePoints(int n, double start, double stop) 12 | { 13 | m_Points = arma::logspace(start, stop, n); 14 | return true; 15 | } 16 | 17 | bool RunSection::ActionLogSpace::DoStep() 18 | { 19 | // Make sure we have an ActionScaler to act on 20 | 21 | if (actionScaler == nullptr || !this->IsValid()) 22 | { 23 | return false; 24 | } 25 | 26 | double val = 0; 27 | GetPoint(val); 28 | 29 | if (!this->actionScaler->Set(val)) 30 | { 31 | return false; 32 | } 33 | return true; 34 | } 35 | 36 | bool RunSection::ActionLogSpace::DoValidate() 37 | { 38 | std::string str; 39 | if (!this->Properties()->Get("actionscalar", str) && !this->Properties()->Get("scalar", str)) 40 | { 41 | std::cout << "ERROR: No ActionScalar specified for the LogSpace action \"" << this->Name() << "\"!" << std::endl; 42 | return false; 43 | } 44 | int NumPoints = 0; 45 | if (!this->Properties()->Get("points", NumPoints)) 46 | { 47 | std::cout << "ERROR: No Number of points specified for the LogSpace action \"" << this->Name() << "\"!" << std::endl; 48 | return false; 49 | } 50 | double lowbounds = 0; 51 | if (!this->Properties()->Get("minvalue", lowbounds) && !this->Properties()->Get("min", lowbounds)) 52 | { 53 | std::cout << "ERROR: No miniumum value specified for the LogSpace action \"" << this->Name() << "\"!" << std::endl; 54 | return false; 55 | } 56 | double upbounds = 0; 57 | if (!this->Properties()->Get("maxvalue", upbounds) && !this->Properties()->Get("max", upbounds)) 58 | { 59 | std::cout << "ERROR: No maximum value specified for the LogSpace action \"" << this->Name() << "\"!" << std::endl; 60 | return false; 61 | } 62 | 63 | if (lowbounds >= upbounds) 64 | { 65 | std::cout << "ERROR: No incorrect bounds specified for the LogSpace action \"" << this->Name() << "\"!" << std::endl; 66 | return false; 67 | } 68 | 69 | m_Num = NumPoints; 70 | m_Bounds = {lowbounds, upbounds}; 71 | 72 | // Attemp to set the ActionVector 73 | if (!this->Scalar(str, &(this->actionScaler))) 74 | { 75 | std::cout << "ERROR: Could not find ActionScaler \"" << str << "\" specified for the LogSpace action \"" << this->Name() << "\"!" << std::endl; 76 | return false; 77 | } 78 | 79 | if (this->actionScaler->IsReadonly()) 80 | { 81 | std::cout << "ERROR: Read only ActionScaler \"" << str << "\" specified for the LogSpace action \"" << this->Name() << "\"! Cannot act on this scaler!" << std::endl; 82 | return false; 83 | } 84 | 85 | CalculatePoints(m_Num, m_Bounds.first, m_Bounds.second); 86 | 87 | double val = 0; 88 | GetPoint(val); 89 | std::cout << val << std::endl; 90 | if (!this->actionScaler->Set(val)) 91 | { 92 | 93 | return false; 94 | } 95 | return true; 96 | } 97 | 98 | bool RunSection::ActionLogSpace::Reset() 99 | { 100 | m_Step = 0; 101 | double val = 0; 102 | GetPoint(val); 103 | this->actionScaler->Set(val); 104 | return true; 105 | } 106 | 107 | RunSection::ActionLogSpace::ActionLogSpace(const MSDParser::ObjectParser &_parser, const std::map &_scaler, const std::map &_vector) 108 | : Action(_parser, _scaler, _vector) 109 | { 110 | m_Step = 0; 111 | m_Num = 0; 112 | m_Bounds = {0.0, 0.0}; 113 | m_Points = arma::rowvec(arma::zeros(m_Num)); 114 | } 115 | 116 | bool RunSection::ActionLogSpace::GetPoint(double &val) 117 | { 118 | val = m_Points[m_Step]; 119 | m_Step++; 120 | return true; 121 | } 122 | -------------------------------------------------------------------------------- /SpinAPI/Transition.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // Transition class (SpinAPI Module) 3 | // ------------------ 4 | // Describes reaction operators. 5 | // 6 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 7 | // (c) 2025 Quantum Biology and Computational Physics Group. 8 | // See LICENSE.txt for license information. 9 | ///////////////////////////////////////////////////////////////////////// 10 | #ifndef MOD_SpinAPI_Transition 11 | #define MOD_SpinAPI_Transition 12 | 13 | #include 14 | #include "Trajectory.h" 15 | #include "SpinSystem.h" 16 | #include "MSDParserfwd.h" 17 | 18 | namespace SpinAPI 19 | { 20 | class Transition 21 | { 22 | private: 23 | // Implementation details 24 | std::shared_ptr system; 25 | std::shared_ptr target; 26 | std::shared_ptr properties; 27 | double rate; 28 | TransitionType type; 29 | state_ptr sourcestate; 30 | state_ptr targetstate; 31 | ReactionOperatorType reactionOperators; 32 | bool isValid; 33 | 34 | // Trajectory parameters 35 | Trajectory trajectory; 36 | bool trjHasTime; 37 | bool trjHasRate; 38 | bool trjRateIsLifetime; // Whether lifetime was specified instead of rate (trjRate will then point to the lifetime column) 39 | unsigned int trjTime; 40 | unsigned int trjRate; 41 | 42 | // Private methods to create ActionTargets 43 | std::vector CreateActionScalars(const std::string &); 44 | 45 | public: 46 | // Constructors / Destructors 47 | Transition(std::string, std::string, std::shared_ptr); // Normal constructor 48 | Transition(const Transition &); // Copy-constructor 49 | ~Transition(); // Destructor 50 | 51 | // Operators 52 | const Transition &operator=(const Transition &); // Copy-assignment 53 | 54 | // Name and validation 55 | std::string Name() const; 56 | bool Validate(const std::vector> &_systems); // A validation method that gets the state_ptrs from the systems 57 | bool IsValid() const; 58 | bool HasTrajectory() const; 59 | 60 | void SetValid(bool valid) 61 | { 62 | isValid = valid; 63 | } 64 | 65 | // Public property methods 66 | double Rate() const; 67 | TransitionType Type() const; 68 | std::shared_ptr System() const; 69 | std::shared_ptr Target() const; 70 | state_ptr SourceState() const; 71 | state_ptr TargetState() const; 72 | ReactionOperatorType GetReactionOperatorType() const; 73 | unsigned int TrajectoryLength() const; // Number of steps in the trajectory (0 means no trajectory) 74 | bool SetTrajectoryStep(unsigned int); // Set the rate based on a trajectory 75 | bool SetTime(double); // Set the rate based on a trajectory 76 | 77 | // Allow access to custom properties to be used for custom tasks 78 | std::shared_ptr Properties() const; 79 | 80 | // Spin subspace methods 81 | bool IsComplete(const std::vector &) const; // Checks whether any spins in the source state are coupled/entangled to any spins outside the source state 82 | bool IsTargetComplete(const std::vector &) const; // Checks whether any spins in the target state are coupled/entangled to any spins outside the target state 83 | bool CompleteSet(std::vector &) const; // Extends the set such that all spins inside the source state can only be coupled/entangled to other spins inside the source state 84 | bool CompleteTargetSet(std::vector &) const; // Extends the set such that all spins inside the target state can only be coupled/entangled to other spins inside the target state 85 | 86 | // Public method for creating ActionTargets 87 | void GetActionTargets(std::vector &, std::vector &, const std::string &); 88 | }; 89 | 90 | // Define alias for transition-pointers 91 | using transition_ptr = std::shared_ptr; 92 | 93 | // Non-member non-friend functions 94 | bool IsValid(const Transition &); 95 | bool IsStatic(const Transition &); 96 | bool HasTrajectory(const Transition &); 97 | 98 | // Non-member non-friend functions for ActionTarget validation 99 | bool CheckActionScalarTransitionRate(const double &); 100 | } 101 | 102 | #endif 103 | -------------------------------------------------------------------------------- /Tests/testmain.cpp: -------------------------------------------------------------------------------- 1 | ////////////////////////////////////////////////////////////////////////////// 2 | // MolSpin Unit Testing Module 3 | // 4 | // Note: Strictly speaking the tests here are not unit tests, since some test 5 | // functions contain more than a single test, and since most classes/methods/ 6 | // functions are not tested in complete isolation. But the tests are still 7 | // testing various crucial functionalities. 8 | // 9 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 10 | // (c) 2025 Quantum Biology and Computational Physics Group. 11 | // See LICENSE.txt for license information. 12 | ////////////////////////////////////////////////////////////////////////////// 13 | #include 14 | #include 15 | #include 16 | 17 | #include "Tensor.h" 18 | #include "RunSection.h" 19 | ////////////////////////////////////////////////////////////////////////////// 20 | using test_ptr = bool (*)(); // Function pointer alias 21 | using test_case = std::pair; // Function pointer and name 22 | ////////////////////////////////////////////////////////////////////////////// 23 | // Include various testing functions 24 | #include "assertfunctions.cpp" 25 | ////////////////////////////////////////////////////////////////////////////// 26 | // Files with the other test functions 27 | #include "tests_spinapi.cpp" 28 | #include "tests_msdparser.cpp" 29 | #include "tests_actions.cpp" 30 | #include "tests_TaskStaticHSSymmetricDecay.cpp" 31 | #include "tests_TaskStaticSS.cpp" 32 | #include "tests_TaskStaticRPOnlyHSSymDec.cpp" 33 | #include "tests_TaskStaticSSSpectra.cpp" 34 | #include "tests_utility.cpp" 35 | ////////////////////////////////////////////////////////////////////////////// 36 | // A simple test to test the test module itself 37 | bool this_is_a_test_of_the_test_module() 38 | { 39 | return true; 40 | } 41 | ////////////////////////////////////////////////////////////////////////////// 42 | int main(int argc, char **argv) 43 | { 44 | std::cout << "# -------------------------------------------------------" << std::endl; 45 | std::cout << "# Molecular Spin Dynamics" << std::endl; 46 | std::cout << "# " << std::endl; 47 | std::cout << "# Developed 2017-2019 by Claus Nielsen and 2021-2022 by Luca Gerhards." << std::endl; 48 | std::cout << "# (c) Quantum Biology and Computational Physics Group," << std::endl; 49 | std::cout << "# Carl von Ossietzky University of Oldenburg." << std::endl; 50 | std::cout << "# For more information see www.molspin.eu" << std::endl; 51 | std::cout << "# -------------------------------------------------------" << std::endl; 52 | std::cout << "# Unit Testing Module" << std::endl; 53 | std::cout << "# -------------------------------------------------------" << std::endl; 54 | 55 | // Collections of test cases 56 | std::vector cases; 57 | std::vector failed_cases; 58 | 59 | // Add test cases to the list 60 | cases.push_back(test_case("Test module", this_is_a_test_of_the_test_module)); 61 | AddSpinAPITests(cases); 62 | AddMSDParserTests(cases); 63 | AddActionsTests(cases); 64 | AddTaskStaticHSSymmetricDecayTests(cases); 65 | AddTaskStaticSSTests(cases); 66 | AddTaskStaticRPOnlyHSSymDecTests(cases); 67 | AddTaskStaticSSSpectraTests(cases); 68 | AddUtiltiyTests(cases); 69 | 70 | 71 | // Loop through all test cases and test them 72 | for (auto i = cases.cbegin(); i != cases.cend(); i++) 73 | { 74 | std::cout << "Running test \"" << i->first << "\" ......... " << std::flush; 75 | if (i->second()) 76 | { 77 | std::cout << "PASSED!"; 78 | } 79 | else 80 | { 81 | std::cout << "FAILED!"; 82 | failed_cases.push_back(*i); 83 | } 84 | std::cout << std::endl; 85 | } 86 | 87 | // Get number of passed and failed tests 88 | int failed = failed_cases.size(); 89 | int passed = cases.size() - failed; 90 | 91 | // Get summary at the end 92 | std::cout << "# -------------------------------------------------------" << std::endl; 93 | std::cout << "Testing done!\nPassed: " << passed << "\nFailed: " << failed << "\nTotal: " << cases.size() << std::endl; 94 | 95 | // Notify which cases has failed 96 | if (failed > 0) 97 | { 98 | std::cout << "\nThere were failed test cases:" << std::endl; 99 | for (auto i = failed_cases.cbegin(); i != failed_cases.cend(); i++) 100 | std::cout << " - " << i->first << std::endl; 101 | } 102 | } 103 | ////////////////////////////////////////////////////////////////////////////// 104 | -------------------------------------------------------------------------------- /RunSection/RunSection.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // RunSection (RunSection module) 3 | // ------------------ 4 | // Class that keeps track of all objects generated from the MSDParser 5 | // module, and is responsible for keeping track of the calculation step 6 | // to run, triggering actions, and running task classes. 7 | // 8 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 9 | // (c) 2025 Quantum Biology and Computational Physics Group. 10 | // See LICENSE.txt for license information. 11 | ///////////////////////////////////////////////////////////////////////// 12 | #ifndef MOD_RunSection_RunSection 13 | #define MOD_RunSection_RunSection 14 | 15 | #include 16 | #include 17 | #include 18 | #include "MSDParserDefines.h" 19 | #include "MSDParserfwd.h" 20 | #include "RunSectionfwd.h" 21 | #include "ActionTarget.h" 22 | #include "SpinAPIfwd.h" 23 | 24 | namespace RunSection 25 | { 26 | class RunSection 27 | { 28 | private: 29 | // Store pointers to the tasks and actions to avoid the splicing problem 30 | std::vector> tasks; // Calculations, save/load, etc. 31 | std::vector> actions; // Actions to be performed at each step 32 | std::vector outputs; // StandardOutput objects to provide information about action targets 33 | std::shared_ptr settings; 34 | 35 | // Collections of SpinAPI objects 36 | std::vector> systems; 37 | 38 | // Associate containers of ActionTargets 39 | std::map actionScalars; 40 | std::map actionVectors; 41 | 42 | // Commandline options 43 | bool overruleAppend; // "--append"/"-a" 44 | bool noCalculations; // "--no-calc"/"-z" 45 | 46 | // Method that creates task objects - add new task classes here 47 | // NOTE: Located in the seperate file "RunSection_CreateTask.cpp" 48 | std::shared_ptr CreateTask(const std::string &, const MSDParser::ObjectParser &); 49 | 50 | public: 51 | // public variables 52 | 53 | // Constructors / Destructors 54 | RunSection(); // Normal constructor 55 | RunSection(const RunSection &) = delete; // Disable Copy-constructor 56 | ~RunSection(); // Destructor 57 | 58 | // Operators 59 | const RunSection &operator=(const RunSection &) = delete; // Disable Copy-assignment 60 | 61 | // Public non-const methods 62 | bool Run(unsigned int); // Execute the Run section 63 | bool Run(std::string, unsigned int); // Execute the Run section starting from the task with the given name. Nothing is run if the name was not found 64 | bool Step(unsigned int); // Advance a single step (i.e. calling actions), with the current step number 65 | bool Add(MSDParser::ObjectType, const MSDParser::ObjectParser &); // Add objects 66 | bool Add(std::string, const ActionScalar &); 67 | bool Add(std::string, const ActionVector &); 68 | bool Add(std::shared_ptr); 69 | bool Add(const SpinAPI::output_ptr &); 70 | 71 | // Public get-object-by-name methods 72 | std::shared_ptr GetTask(const std::string &); 73 | // std::vector> GetActions() const { return this->actions; }; 74 | 75 | // Methods to get ActionTargets 76 | std::map GetActionScalars(); 77 | std::map GetActionVectors(); 78 | 79 | // Public const methods 80 | std::shared_ptr GetSettings() const { return this->settings; }; 81 | void PrintSystems(bool) const; 82 | 83 | // Set the commandline options 84 | void SetOverruleAppend(bool _overruleAppend) { this->overruleAppend = _overruleAppend; }; // "--append"/"-a" 85 | void SetNoCalculationsMode(bool _noCalculations) { this->noCalculations = _noCalculations; }; // "--no-calc"/"-z" 86 | 87 | // Public output object methods 88 | bool WriteOutputHeader(std::ostream &) const; // Writes the headers for the output columns 89 | bool WriteOutput(std::ostream &) const; // Writes standard output (information about action targets) 90 | 91 | // void SetThreads(int value) 92 | //{ 93 | // threads = value; 94 | // } 95 | 96 | // int GetThreads() 97 | //{ 98 | // return threads; 99 | // } 100 | // BasicTask can access SpinSystems and Settings to pass on to child task classes 101 | friend class BasicTask; 102 | }; 103 | } 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /RunSection/BasicTask.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // BasicTask (RunSection module) 3 | // ------------------ 4 | // Base class for task/calculation methods that go in the Run section 5 | // of the input file. I.e. all types of calculation (time integration, 6 | // time propagation, eigenvalue calculation, etc.) is implemented as a 7 | // class inheriting BasicTask. 8 | // 9 | // A RunSection contains a list of BasicTasks whoose Run methods are 10 | // called on every step. 11 | // 12 | // The BasicTask class has access to all the loaded information from 13 | // the input file, i.e. properties of spins, interactions, etc. 14 | // ------------------ 15 | // Molecular Spin Dynamics Software - developed by Claus Nielsen and Luca Gerhards. 16 | // (c) 2025 Quantum Biology and Computational Physics Group. 17 | // See LICENSE.txt for license information. 18 | ///////////////////////////////////////////////////////////////////////// 19 | #ifndef MOD_RunSection_BasicTask 20 | #define MOD_RunSection_BasicTask 21 | 22 | #include 23 | #include 24 | #include "OutputHandler.h" 25 | #include "RunSectionfwd.h" 26 | #include "MSDParserfwd.h" 27 | #include "SpinAPIfwd.h" 28 | #include "ActionTarget.h" 29 | 30 | namespace RunSection 31 | { 32 | 33 | enum class Propagator 34 | { 35 | Default = 0, //whatever the timeevo class chooses 36 | exp = 1, 37 | RK4 = 2, 38 | RK45 = 3 39 | }; 40 | class BasicTask 41 | { 42 | private: 43 | // Implementation 44 | std::shared_ptr properties; // Use a pointer to the object to minimize compilation dependencies 45 | const RunSection &runsection; 46 | OutputHandler output; 47 | bool isValid; 48 | bool isValidated; 49 | const std::map *scalars; 50 | const std::map *vectors; 51 | std::map> usedScalars; 52 | std::map> usedVectors; 53 | 54 | // Private method that calls the pure virtual Validate method, and allows BasicTask to do some extra initialization first 55 | // (i.e. setting the notification level, as that cannot be done in the constructor since the runsection.settings object must be properly loaded first) 56 | bool DoValidation(); 57 | 58 | // Other private methods 59 | void ResetTimeAndTrajectoryStep(); 60 | 61 | protected: 62 | // Run methods to be overwritten in derived classes 63 | virtual bool RunLocal() = 0; // Normal run method for a single workstation 64 | virtual bool RunMPI(); // MPI run method to use on a supercomputer cluster (not required to be implemented) 65 | virtual bool Validate() = 0; // Method to validate the task, i.e. to check that it has the required parameters etc. 66 | 67 | virtual void SelectPropagator(std::string str); //Method to choose the Propagator for timeevo tasks 68 | 69 | // Allow access to settings, properties, spin systems, etc. for derived classes 70 | std::shared_ptr RunSettings() const; 71 | std::vector SpinSystems() const; 72 | const std::shared_ptr &Properties() const; 73 | std::ostream &Log(const MessageType &_msgtype = MessageType_Normal); 74 | std::ostream &Data(); 75 | bool WriteStandardOutputHeader(std::ostream &); 76 | bool WriteStandardOutput(std::ostream &); 77 | 78 | // ActionTarget access 79 | bool Scalar(std::string _name, ActionScalar **_scalar = nullptr); 80 | bool Vector(std::string _name, ActionVector **_vector = nullptr); 81 | 82 | Propagator prop; 83 | 84 | public: 85 | // Constructors / Destructors 86 | BasicTask(const MSDParser::ObjectParser &, const RunSection &); // Normal constructor 87 | BasicTask(const BasicTask &) = delete; // Default Copy-constructor - no need to copy a BasicTask which could cause splicing problems 88 | virtual ~BasicTask(); // Destructor 89 | 90 | // Operators 91 | BasicTask &operator=(const BasicTask &) = delete; // Default Copy-assignment 92 | 93 | // Public methods 94 | bool Run(); 95 | bool IsValid(); 96 | std::string Name(); 97 | 98 | // Method to provide BasicTask with access to ActionTargets 99 | void SetActionTargets(const std::map &, const std::map &); 100 | 101 | // Methods to change the Log and Data stream 102 | bool SetLogStream(std::ostream &); 103 | bool SetDataStream(std::ostream &); 104 | 105 | }; 106 | } 107 | 108 | #endif 109 | -------------------------------------------------------------------------------- /SpinAPI/Pulse.h: -------------------------------------------------------------------------------- 1 | ///////////////////////////////////////////////////////////////////////// 2 | // Operator class (SpinAPI Module) developed by Luca Gerhards and Irina Anisimova. 3 | // ------------------ 4 | // Special operators to be used in some task types. 5 | // 6 | // Molecular Spin Dynamics Software - developed by Luca Gerhards. 7 | // (c) 2024 Quantum Biology and Computational Physics Group. 8 | // See LICENSE.txt for license information. 9 | ///////////////////////////////////////////////////////////////////////// 10 | #ifndef MOD_SpinAPI_Pulse 11 | #define MOD_SpinAPI_Pulse 12 | 13 | #include 14 | #include 15 | #include "SpinAPIDefines.h" 16 | #include "MSDParserfwd.h" 17 | #include "SpinAPIfwd.h" 18 | #include "ActionTarget.h" 19 | 20 | namespace SpinAPI 21 | { 22 | class Pulse 23 | { 24 | private: 25 | // Implementation details 26 | std::shared_ptr properties; 27 | PulseType type; // Different Pulsetype options are available 28 | std::vector group; // Spins that are affected by the pulse 29 | double timestep; // Timestep with which propagation should be done 30 | arma::vec rotationaxis; // Direction around which a pulse should rotate 31 | double angle; // Rotation around a certain direction with angler (deg) 32 | double pulsetime; // Time of the applied pulse (ns) 33 | arma::vec field; // Magnetic field strength of pulse (T) 34 | double frequency; // Frequency of the applied field in HHz; 35 | std::vector addCommonPrefactorList; // Whether or not to multiply by "mu_B" for electronic spins, or the equivalent for nuclear spins 36 | std::vector ignoreTensorsList; // Whether or not to multiply by "g" for the spins 37 | std::vector prefactorList; // Spins that are affected by the pulse 38 | 39 | // Helper method called by ParseSpinGroups 40 | bool AddSpinList(const std::string&, const std::vector&, std::vector&, const std::vector* _crossCheck = nullptr); 41 | 42 | // Private methods to create ActionTargets 43 | std::vector CreateActionVectors(const std::string&); 44 | std::vector CreateActionScalars(const std::string&); 45 | 46 | public: 47 | // Constructors / Destructors 48 | Pulse(std::string, std::string); // Normal constructor 49 | Pulse(const Pulse&); // Copy-constructor 50 | ~Pulse(); // Destructor 51 | 52 | // Operator 53 | const Pulse& operator=(const Pulse&); // Copy-assignment 54 | 55 | // Read spins into group1 and group2, returns false if some spins were not found 56 | bool ParseSpinGroups(const std::vector&); 57 | 58 | // Name and validation 59 | std::string Name() const; 60 | bool Validate(const std::vector>&); 61 | bool IsValid() const; 62 | 63 | // Public property methods 64 | PulseType Type() const {return this->type;}; 65 | std::vector Group() const {return this->group;}; 66 | const std::vector AddCommonPrefactorList() const {return this->addCommonPrefactorList;}; 67 | const std::vector IgnoreTensorsList() const { return this->ignoreTensorsList;}; 68 | const double Timestep() const; 69 | const arma::vec Rotationaxis() const; 70 | const double Angle() const; 71 | const double Pulsetime() const; 72 | const arma::vec Field() const; 73 | const double Frequency() const; 74 | const arma::vec PrefactorList() const; 75 | 76 | 77 | // Allow access to custom properties to be used for custom tasks 78 | std::shared_ptr Properties() const; 79 | 80 | 81 | // Public method for creating ActionTargets 82 | void GetActionTargets(std::vector&, std::vector&, const std::string&); 83 | }; 84 | 85 | // Define alias for Operator-pointers 86 | using pulse_ptr = std::shared_ptr; 87 | 88 | PulseType Type(const Pulse&); 89 | 90 | // Non-member non-friend functions 91 | bool IsValid(const Pulse&); 92 | 93 | // Non-member non-friend functions for ActionTarget validation 94 | bool CheckActionVectorPulseField(const arma::vec &); 95 | bool CheckActionScalarPulseScalar(const double &); 96 | } 97 | 98 | #endif 99 | -------------------------------------------------------------------------------- /Example/performance_redfield/example_3.msd: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------- 2 | // MolSpin Input file example 3 | // See the user manual for more information 4 | // Find it at www.molspin.eu 5 | // ------------------------------------------------------------- 6 | SpinSystem system1 7 | { 8 | // --------------------------------------------------------- 9 | // Spins 10 | // --------------------------------------------------------- 11 | Spin RPElectron1 12 | { 13 | type = electron; 14 | spin = 1/2; 15 | tensor = isotropic(2.0023); 16 | } 17 | 18 | Spin RPElectron2 19 | { 20 | type = electron; 21 | spin = 1/2; 22 | tensor = isotropic(2.0023); 23 | } 24 | 25 | Spin H1 26 | { 27 | type = nucleus; 28 | spin = 1/2; 29 | } 30 | 31 | Spin H2 32 | { 33 | type = nucleus; 34 | spin = 1/2; 35 | } 36 | 37 | Spin H3 38 | { 39 | type = nucleus; 40 | spin = 1/2; 41 | } 42 | 43 | 44 | // ------------------------- 45 | // Zeeman interaction 46 | // ------------------------- 47 | 48 | Interaction zeeman1 49 | { 50 | type = zeeman; 51 | field = "0 0 0.5"; 52 | spins = RPElectron1; 53 | tau_c = 0.1; 54 | g = 1; 55 | coeff = 0; 56 | 57 | } 58 | 59 | Interaction zeeman2 60 | { 61 | type = zeeman; 62 | field = "0 0 0.5"; 63 | spins = RPElectron2; 64 | tau_c = 0.1; 65 | g = 1; 66 | coeff = 0; 67 | } 68 | 69 | // ------------------------- 70 | // Hyperfine interactions 71 | // ------------------------- 72 | Interaction radical1hyperfine 73 | { prefactor = 1e-3; 74 | type = hyperfine; 75 | group1 = RPElectron1, RPElectron2; 76 | group2 = H1,H2,H3; 77 | tensor = matrix("0.5 0.0 0.0;0.0 0.5 0.0;0.0 0.0 2.0");; 78 | tau_c = 0.1; 79 | g = 1; 80 | coeff = 0; 81 | } 82 | 83 | // ------------------------- 84 | // Spin States 85 | // --------------------------------------------------------- 86 | 87 | State Singlet // |S> 88 | { 89 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> - |-1/2,1/2>; 90 | } 91 | 92 | State T0 // |T0> 93 | { 94 | spins(RPElectron1,RPElectron2) = |1/2,-1/2> + |-1/2,1/2>; 95 | } 96 | 97 | State Tp // |T+> 98 | { 99 | spin(RPElectron2) = |1/2>; 100 | spin(RPElectron1) = |1/2>; 101 | } 102 | 103 | State Tm // |T-> 104 | { 105 | spin(RPElectron2) = |-1/2>; 106 | spin(RPElectron1) = |-1/2>; 107 | } 108 | State Identity 109 | { 110 | } 111 | 112 | // --------------------------------------------------------- 113 | // Transitions 114 | // --------------------------------------------------------- 115 | Transition Product1 116 | { 117 | type = sink; 118 | source = Singlet; 119 | rate =0.001 ; 120 | } 121 | 122 | Transition Product4 123 | { 124 | type = sink; 125 | source = T0; 126 | rate =0.001; 127 | } 128 | 129 | Transition Product5 130 | { 131 | type = sink; 132 | source = Tp; 133 | rate =0.001; 134 | } 135 | 136 | Transition Product6 137 | { 138 | type = sink; 139 | source = Tm; 140 | rate =0.001; 141 | } 142 | 143 | 144 | // ------------------------- 145 | // Spin system properties 146 | // ------------------------- 147 | Properties properties 148 | { 149 | initialstate = Singlet; 150 | } 151 | } 152 | // ------------------------------------------------------------- 153 | Settings 154 | { 155 | Settings general 156 | { 157 | steps = 1; //88; 158 | notifications = details; 159 | } 160 | 161 | Action scan 162 | { 163 | type = rotatevector; 164 | vector = system1.zeeman1.field; 165 | axis = "0 1 0"; 166 | value = 90; 167 | } 168 | 169 | Output orientation 170 | { 171 | type = vectorangle; 172 | vector = system1.zeeman1.field; 173 | reference = " 0 0 1"; 174 | } 175 | } 176 | // ------------------------------------------------------------- 177 | Run 178 | { 179 | // Task Method1 180 | // { 181 | // type = StaticSS; 182 | // logfile = "example_staticss.log"; 183 | // datafile = "example_staticss.dat"; 184 | // transitionyields = true; 185 | // } 186 | 187 | Task Method2 188 | { 189 | type = redfield-relaxation; 190 | logfile = "redfield-relaxation.log"; 191 | datafile = "redfield-relaxation.dat"; 192 | transitionyields = true; 193 | 194 | } 195 | 196 | } 197 | 198 | --------------------------------------------------------------------------------