Line data Source code
1 : /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 : Copyright (c) 2013-2020 The plumed team 3 : (see the PEOPLE file at the root of the distribution for a list of names) 4 : 5 : See http://www.plumed.org for more information. 6 : 7 : This file is part of plumed, version 2. 8 : 9 : plumed is free software: you can redistribute it and/or modify 10 : it under the terms of the GNU Lesser General Public License as published by 11 : the Free Software Foundation, either version 3 of the License, or 12 : (at your option) any later version. 13 : 14 : plumed is distributed in the hope that it will be useful, 15 : but WITHOUT ANY WARRANTY; without even the implied warranty of 16 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 : GNU Lesser General Public License for more details. 18 : 19 : You should have received a copy of the GNU Lesser General Public License 20 : along with plumed. If not, see <http://www.gnu.org/licenses/>. 21 : +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */ 22 : #include "core/ActionRegister.h" 23 : #include "core/ActionShortcut.h" 24 : 25 : //+PLUMEDOC MCOLVAR DETERMINANT 26 : /* 27 : Calculate the determinant of a matrix 28 : 29 : This shorctu allows you to calculate the [determinant](https://en.wikipedia.org/wiki/Determinant) of 30 : a square matrix. The following example shows how the action is used: 31 : 32 : ```plumed 33 : d1: DISTANCE_MATRIX ATOMS=1-5 34 : det: DETERMINANT ARG=d1 35 : PRINT ARG=det FILE=colvar 36 : ``` 37 : 38 : If you look at the expanded version of the input above you can see that PLUMED calculates the determinant 39 : by first diagonalising the input matrix and then calculating the product of the eigenvalues. 40 : 41 : */ 42 : //+ENDPLUMEDOC 43 : 44 : namespace PLMD { 45 : namespace matrixtools { 46 : 47 : class Determinant : public ActionShortcut { 48 : public: 49 : static void registerKeywords( Keywords& keys ); 50 : explicit Determinant(const ActionOptions&ao); 51 : }; 52 : 53 : PLUMED_REGISTER_ACTION(Determinant,"DETERMINANT") 54 : 55 2 : void Determinant::registerKeywords( Keywords& keys ) { 56 2 : ActionShortcut::registerKeywords(keys); 57 4 : keys.addInputKeyword("compulsory","ARG","matrix","The matrix that we are calculating the determinant for"); 58 4 : keys.setValueDescription("scalar","the determinant of the matrix"); 59 2 : keys.needsAction("DIAGONALIZE"); 60 2 : keys.needsAction("PRODUCT"); 61 2 : } 62 : 63 0 : Determinant::Determinant( const ActionOptions& ao): 64 : Action(ao), 65 0 : ActionShortcut(ao) { 66 : std::string arg; 67 0 : parse("ARG",arg); 68 : // Compose a vector from the args 69 0 : readInputLine( getShortcutLabel() + "_diag: DIAGONALIZE ARG=" + arg + " VECTORS=all"); 70 : // Not sure about the regexp here - check with matrix with more than 10 rows 71 0 : readInputLine( getShortcutLabel() + ": PRODUCT ARG=(" + getShortcutLabel() + "_diag\.vals-[0-9])"); 72 0 : } 73 : 74 : } 75 : }