source: src/Box.cpp@ 3f9eba

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 3f9eba was 66fd49, checked in by Frederik Heber <heber@…>, 14 years ago

Rewrite of FillVoidWithMoleculeAction.

FillVoidWithMoleculeAction:

  • new parameter MinDistance and default value of 0.
  • BUGFIX: filler is already created when parsing file, removed useless creation of it initially (also caused lots of confusion due to an "extra" molecule).
  • Undo implemented, regression test inserted.
  • Redo is somewhat hard to implement, as one would use performCall() if it only it would not retrieve its values from ValueStorage ...

FillVoidWithMolecule():

  • filler is now the zeroth not the last molecule, marked by firstInsertion and firstInserter. Filler is removed if no molecules are filled.
  • outsourced stuff into smaller functions
  • removed FillIt to through every atom despite only CurrentPosition, indepedent of atom position, is checked.

TESTFIXES:

  • Analysis/3: test.xyz changed because boundary is now 1.5 instead of 2.1 as 2.1 is not enough of molecules get filled in (and the filler already is).
  • Analysis/3: tensid.data was actually lacking water at (0,0,0) which is after the rewrite present.
  • Property mode set to 100644
File size: 7.5 KB
Line 
1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2010 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * Box.cpp
10 *
11 * Created on: Jun 30, 2010
12 * Author: crueger
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include "CodePatterns/MemDebug.hpp"
21
22#include "Box.hpp"
23
24#include <cmath>
25#include <iostream>
26#include <cstdlib>
27
28#include "LinearAlgebra/RealSpaceMatrix.hpp"
29#include "LinearAlgebra/Vector.hpp"
30#include "LinearAlgebra/Plane.hpp"
31#include "Shapes/BaseShapes.hpp"
32#include "Shapes/ShapeOps.hpp"
33
34#include "CodePatterns/Assert.hpp"
35#include "CodePatterns/Log.hpp"
36#include "CodePatterns/Verbose.hpp"
37
38using namespace std;
39
40Box::Box()
41{
42 M= new RealSpaceMatrix();
43 M->setIdentity();
44 Minv = new RealSpaceMatrix();
45 Minv->setIdentity();
46 conditions.resize(3);
47 conditions[0] = conditions[1] = conditions[2] = Wrap;
48}
49
50Box::Box(const Box& src){
51 M=new RealSpaceMatrix(*src.M);
52 Minv = new RealSpaceMatrix(*src.Minv);
53 conditions = src.conditions;
54}
55
56Box::~Box()
57{
58 delete M;
59 delete Minv;
60}
61
62const RealSpaceMatrix &Box::getM() const{
63 return *M;
64}
65const RealSpaceMatrix &Box::getMinv() const{
66 return *Minv;
67}
68
69void Box::setM(RealSpaceMatrix _M){
70 ASSERT(_M.determinant()!=0,"Matrix in Box construction was not invertible");
71 *M =_M;
72 *Minv = M->invert();
73}
74
75Vector Box::translateIn(const Vector &point) const{
76 return (*M) * point;
77}
78
79Vector Box::translateOut(const Vector &point) const{
80 return (*Minv) * point;
81}
82
83Vector Box::WrapPeriodically(const Vector &point) const{
84 Vector helper = translateOut(point);
85 for(int i=NDIM;i--;){
86
87 switch(conditions[i]){
88 case Wrap:
89 helper.at(i)=fmod(helper.at(i),1);
90 helper.at(i)+=(helper.at(i)>=0)?0:1;
91 break;
92 case Bounce:
93 {
94 // there probably is a better way to handle this...
95 // all the fabs and fmod modf probably makes it very slow
96 double intpart,fracpart;
97 fracpart = modf(fabs(helper.at(i)),&intpart);
98 helper.at(i) = fabs(fracpart-fmod(intpart,2));
99 }
100 break;
101 case Ignore:
102 break;
103 default:
104 ASSERT(0,"No default case for this");
105 }
106
107 }
108 return translateIn(helper);
109}
110
111bool Box::isInside(const Vector &point) const
112{
113 bool result = true;
114 Vector tester = translateOut(point);
115
116 for(int i=0;i<NDIM;i++)
117 result = result &&
118 ((conditions[i] == Ignore) ||
119 ((tester[i] >= -MYEPSILON) &&
120 ((tester[i] - 1.) < MYEPSILON)));
121
122 return result;
123}
124
125
126VECTORSET(std::list) Box::explode(const Vector &point,int n) const{
127 ASSERT(isInside(point),"Exploded point not inside Box");
128 VECTORSET(std::list) res;
129
130 Vector translater = translateOut(point);
131 Vector mask; // contains the ignored coordinates
132
133 // count the number of coordinates we need to do
134 int dims = 0; // number of dimensions that are not ignored
135 vector<int> coords;
136 vector<int> index;
137 for(int i=0;i<NDIM;++i){
138 if(conditions[i]==Ignore){
139 mask[i]=translater[i];
140 continue;
141 }
142 coords.push_back(i);
143 index.push_back(-n);
144 dims++;
145 } // there are max vectors in total we need to create
146
147 if(!dims){
148 // all boundaries are ignored
149 res.push_back(point);
150 return res;
151 }
152
153 bool done = false;
154 while(!done){
155 // create this vector
156 Vector helper;
157 for(int i=0;i<dims;++i){
158 switch(conditions[coords[i]]){
159 case Wrap:
160 helper[coords[i]] = index[i]+translater[coords[i]];
161 break;
162 case Bounce:
163 {
164 // Bouncing the coordinate x produces the series:
165 // 0 -> x
166 // 1 -> 2-x
167 // 2 -> 2+x
168 // 3 -> 4-x
169 // 4 -> 4+x
170 // the first number is the next bigger even number (n+n%2)
171 // the next number is the value with alternating sign (x-2*(n%2)*x)
172 // the negative numbers produce the same sequence reversed and shifted
173 int n = abs(index[i]) + ((index[i]<0)?-1:0);
174 int sign = (index[i]<0)?-1:+1;
175 int even = n%2;
176 helper[coords[i]]=n+even+translater[coords[i]]-2*even*translater[coords[i]];
177 helper[coords[i]]*=sign;
178 }
179 break;
180 case Ignore:
181 ASSERT(0,"Ignored coordinate handled in generation loop");
182 default:
183 ASSERT(0,"No default case for this switch-case");
184 }
185
186 }
187 // add back all ignored coordinates (not handled in above loop)
188 helper+=mask;
189 res.push_back(translateIn(helper));
190 // set the new indexes
191 int pos=0;
192 ++index[pos];
193 while(index[pos]>n){
194 index[pos++]=-n;
195 if(pos>=dims) { // it's trying to increase one beyond array... all vectors generated
196 done = true;
197 break;
198 }
199 ++index[pos];
200 }
201 }
202 return res;
203}
204
205VECTORSET(std::list) Box::explode(const Vector &point) const{
206 ASSERT(isInside(point),"Exploded point not inside Box");
207 return explode(point,1);
208}
209
210double Box::periodicDistanceSquared(const Vector &point1,const Vector &point2) const{
211 Vector helper1 = WrapPeriodically(point1);
212 Vector helper2 = WrapPeriodically(point2);
213 VECTORSET(std::list) expansion = explode(helper1);
214 double res = expansion.minDistSquared(helper2);
215 return res;
216}
217
218double Box::periodicDistance(const Vector &point1,const Vector &point2) const{
219 double res;
220 res = sqrt(periodicDistanceSquared(point1,point2));
221 return res;
222}
223
224double Box::DistanceToBoundary(const Vector &point) const
225{
226 std::map<double, Plane> DistanceSet;
227 std::vector<std::pair<Plane,Plane> > Boundaries = getBoundingPlanes();
228 for (int i=0;i<NDIM;++i) {
229 const double tempres1 = Boundaries[i].first.distance(point);
230 const double tempres2 = Boundaries[i].second.distance(point);
231 DistanceSet.insert( make_pair(tempres1, Boundaries[i].first) );
232 DoLog(1) && (Log() << Verbose(1) << "Inserting distance " << tempres1 << " and " << tempres2 << "." << std::endl);
233 DistanceSet.insert( make_pair(tempres2, Boundaries[i].second) );
234 }
235 ASSERT(!DistanceSet.empty(), "Box::DistanceToBoundary() - no distances in map!");
236 return (DistanceSet.begin())->first;
237}
238
239Shape Box::getShape() const{
240 return transform(Cuboid(Vector(0,0,0),Vector(1,1,1)),(*M));
241}
242
243const Box::Conditions_t Box::getConditions() const
244{
245 return conditions;
246}
247
248void Box::setCondition(int i,Box::BoundaryCondition_t condition){
249 conditions[i]=condition;
250}
251
252const vector<pair<Plane,Plane> > Box::getBoundingPlanes() const
253{
254 vector<pair<Plane,Plane> > res;
255 for(int i=0;i<NDIM;++i){
256 Vector base1,base2,base3;
257 base2[(i+1)%NDIM] = 1.;
258 base3[(i+2)%NDIM] = 1.;
259 Plane p1(translateIn(base1),
260 translateIn(base2),
261 translateIn(base3));
262 Vector offset;
263 offset[i]=1;
264 Plane p2(translateIn(base1+offset),
265 translateIn(base2+offset),
266 translateIn(base3+offset));
267 res.push_back(make_pair(p1,p2));
268 }
269 ASSERT(res.size() == 3, "Box::getBoundingPlanes() - does not have three plane pairs!");
270 return res;
271}
272
273void Box::setCuboid(const Vector &endpoint){
274 ASSERT(endpoint[0]>0 && endpoint[1]>0 && endpoint[2]>0,"Vector does not define a full cuboid");
275 M->setIdentity();
276 M->diagonal()=endpoint;
277 Vector &dinv = Minv->diagonal();
278 for(int i=NDIM;i--;)
279 dinv[i]=1/endpoint[i];
280}
281
282Box &Box::operator=(const Box &src){
283 if(&src!=this){
284 delete M;
285 delete Minv;
286 M = new RealSpaceMatrix(*src.M);
287 Minv = new RealSpaceMatrix(*src.Minv);
288 conditions = src.conditions;
289 }
290 return *this;
291}
292
293Box &Box::operator=(const RealSpaceMatrix &mat){
294 setM(mat);
295 return *this;
296}
Note: See TracBrowser for help on using the repository browser.