source: src/Fragmentation/ForceMatrix.cpp@ d4d7a1

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since d4d7a1 was 94d5ac6, checked in by Frederik Heber <heber@…>, 12 years ago

FIX: As we use GSL internally, we are as of now required to use GPL v2 license.

  • GNU Scientific Library is used at every place in the code, especially the sub-package LinearAlgebra is based on it which in turn is used really everywhere in the remainder of MoleCuilder. Hence, we have to use the GPL license for the whole of MoleCuilder. In effect, GPL's COPYING was present all along and stated the terms of the GPL v2 license.
  • Hence, I added the default GPL v2 disclaimer to every source file and removed the note about a (actually missing) LICENSE file.
  • also, I added a help-redistribute action which again gives the disclaimer of the GPL v2.
  • also, I changed in the disclaimer that is printed at every program start in builder_init.cpp.
  • TEST: Added check on GPL statement present in every module to test CodeChecks project-disclaimer.
  • Property mode set to 100644
File size: 6.3 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010-2012 University of Bonn. All rights reserved.
5 *
6 *
7 * This file is part of MoleCuilder.
8 *
9 * MoleCuilder is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation, either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * MoleCuilder 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 General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with MoleCuilder. If not, see <http://www.gnu.org/licenses/>.
21 */
22
23/*
24 * ForceMatrix.cpp
25 *
26 * Created on: Sep 15, 2011
27 * Author: heber
28 */
29
30// include config.h
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35#include "CodePatterns/MemDebug.hpp"
36
37#include <cstring>
38#include <fstream>
39
40#include "CodePatterns/Log.hpp"
41#include "KeySetsContainer.hpp"
42
43#include "Fragmentation/helpers.hpp"
44#include "Helpers/defs.hpp"
45#include "Helpers/helpers.hpp"
46
47#include "ForceMatrix.hpp"
48
49/** Parsing force Indices of each fragment
50 * \param *name directory with \a ForcesFile
51 * \return parsing successful
52 */
53bool ForceMatrix::ParseIndices(const char *name)
54{
55 ifstream input;
56 char *FragmentNumber = NULL;
57 char filename[1023];
58 stringstream line;
59
60 LOG(0, "Parsing force indices for " << MatrixCounter << " matrices.");
61 Indices.resize(MatrixCounter + 1);
62 line << name << FRAGMENTPREFIX << FORCESFILE;
63 input.open(line.str().c_str(), ios::in);
64 //LOG(0, "Opening " << line.str() << " ... " << input);
65 if (input.fail()) {
66 LOG(0, endl << "ForceMatrix::ParseIndices: Unable to open " << line.str() << ", is the directory correct?");
67 return false;
68 }
69 for (int i=0;(i<MatrixCounter) && (!input.eof());i++) {
70 // get the number of atoms for this fragment
71 input.getline(filename, 1023);
72 line.str(filename);
73 // parse the values
74 Indices[i].resize(RowCounter[i]);
75 FragmentNumber = FixedDigitNumber(MatrixCounter, i);
76 //std::stringstream output;
77 //output << FRAGMENTPREFIX << FragmentNumber << "[" << RowCounter[i] << "]:";
78 delete[](FragmentNumber);
79 for(int j=0;(j<RowCounter[i]) && (!line.eof());j++) {
80 line >> Indices[i][j];
81 //output << " " << Indices[i][j];
82 }
83 //LOG(0, output.str());
84 }
85 Indices[MatrixCounter].resize(RowCounter[MatrixCounter]);
86 for(int j=RowCounter[MatrixCounter];j--;) {
87 Indices[MatrixCounter][j] = j;
88 }
89 input.close();
90 return true;
91};
92
93
94/** Sums the forces and puts into last element of \a ForceMatrix::Matrix.
95 * \param Matrix MatrixContainer with matrices (LevelCounter by *ColumnCounter) with all the energies.
96 * \param KeySets KeySetContainer with bond Order and association mapping of each fragment to an order
97 * \param Order bond order
98 * \param sign +1 or -1
99 * \return true if summing was successful
100 */
101bool ForceMatrix::SumSubForces(class ForceMatrix &Fragments, class KeySetsContainer &KeySets, int Order, double sign)
102{
103 int FragmentNr;
104 // sum forces
105 for(int i=0;i<KeySets.FragmentsPerOrder[Order];i++) {
106 FragmentNr = KeySets.OrderSet[Order][i];
107 for(int l=0;l<RowCounter[ FragmentNr ];l++) {
108 int j = Indices[ FragmentNr ][l];
109 if (j > RowCounter[MatrixCounter]) {
110 ELOG(0, "Current force index " << j << " is greater than " << RowCounter[MatrixCounter] << "!");
111 performCriticalExit();
112 return false;
113 }
114 if (j != -1) {
115 //if (j == 0) LOG(0, "Summing onto ion 0, type 0 from fragment " << FragmentNr << ", ion " << l << ".");
116 for(int k=2;k<ColumnCounter[MatrixCounter];k++)
117 Matrix[MatrixCounter][j][k] += sign*Fragments.Matrix[ FragmentNr ][l][k];
118 }
119 }
120 }
121 return true;
122};
123
124
125/** Calls MatrixContainer::ParseFragmentMatrix() and additionally allocates last plus one matrix.
126 * \param *name directory with files
127 * \param *prefix prefix of each matrix file
128 * \param *suffix suffix of each matrix file
129 * \param skiplines number of inital lines to skip
130 * \param skiplines number of inital columns to skip
131 * \return parsing successful
132 */
133bool ForceMatrix::ParseFragmentMatrix(const char *name, const char *prefix, std::string suffix, int skiplines, int skipcolumns)
134{
135 char filename[1023];
136 ifstream input;
137 stringstream file;
138 int nr;
139 bool status = MatrixContainer::ParseFragmentMatrix(name, prefix, suffix, skiplines, skipcolumns);
140
141 if (status) {
142 // count number of atoms for last plus one matrix
143 file << name << FRAGMENTPREFIX << KEYSETFILE;
144 input.open(file.str().c_str(), ios::in);
145 if (input.fail()) {
146 LOG(0, endl << "ForceMatrix::ParseFragmentMatrix: Unable to open " << file.str() << ", is the directory correct?");
147 return false;
148 }
149 RowCounter[MatrixCounter] = 0;
150 while (!input.eof()) {
151 input.getline(filename, 1023);
152 stringstream zeile(filename);
153 while (!zeile.eof()) {
154 zeile >> nr;
155 //LOG(0, "Current index: " << getNr() << ".");
156 if (nr > RowCounter[MatrixCounter])
157 RowCounter[MatrixCounter] = nr;
158 }
159 }
160 RowCounter[MatrixCounter]++; // Nr start at 0, count starts at 1
161 input.close();
162
163 ColumnCounter[MatrixCounter] = 0;
164 for(int j=0; j < MatrixCounter;j++) { // (energy matrix might be bigger than number of atoms in terms of rows)
165 if (ColumnCounter[j] > ColumnCounter[MatrixCounter]) // take maximum of all for last matrix
166 ColumnCounter[MatrixCounter] = ColumnCounter[j];
167 }
168
169 // allocate last plus one matrix
170 if ((int)Matrix[MatrixCounter].size() <= RowCounter[MatrixCounter] + 2)
171 Matrix[MatrixCounter].resize(RowCounter[MatrixCounter] + 1);
172 for(int j=0;j<=RowCounter[MatrixCounter];j++)
173 if ((int)Matrix[MatrixCounter][j].size() <= ColumnCounter[MatrixCounter]+1)
174 Matrix[MatrixCounter][j].resize(ColumnCounter[MatrixCounter]);
175
176 // try independently to parse global forcesuffix file if present
177 strncpy(filename, name, 1023);
178 strncat(filename, prefix, 1023-strlen(filename));
179 strncat(filename, suffix.c_str(), 1023-strlen(filename));
180 std::ifstream input(filename);
181 ParseMatrix(input, skiplines, skipcolumns, MatrixCounter);
182 input.close();
183 }
184
185
186 return status;
187};
Note: See TracBrowser for help on using the repository browser.