Skip to content

Commit 3189d66

Browse files
committed
Boilerplate for handling PBC in restraints. [ci skip]
1 parent f5c8f34 commit 3189d66

18 files changed

Lines changed: 300 additions & 88 deletions

‎corelib/src/libs/SireMM/anglerestraints.cpp‎

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,11 @@ static const RegisterMetaType<AngleRestraints> r_angrests;
227227

228228
QDataStream &operator<<(QDataStream &ds, const AngleRestraints &angrests)
229229
{
230-
writeHeader(ds, r_angrests, 1);
230+
writeHeader(ds, r_angrests, 2);
231231

232232
SharedDataStream sds(ds);
233233

234-
sds << angrests.r
234+
sds << angrests.r << angrests.use_pbc
235235
<< static_cast<const Restraints &>(angrests);
236236

237237
return ds;
@@ -249,8 +249,15 @@ QDataStream &operator>>(QDataStream &ds, AngleRestraints &angrests)
249249
sds >> angrests.r >>
250250
static_cast<Restraints &>(angrests);
251251
}
252+
else if (v == 2)
253+
{
254+
SharedDataStream sds(ds);
255+
256+
sds >> angrests.r >> angrests.use_pbc
257+
>> static_cast<Restraints &>(angrests);
258+
}
252259
else
253-
throw version_error(v, "1", r_angrests, CODELOC);
260+
throw version_error(v, "1,2", r_angrests, CODELOC);
254261

255262
return ds;
256263
}
@@ -303,7 +310,7 @@ AngleRestraints::AngleRestraints(const QString &name,
303310
}
304311

305312
AngleRestraints::AngleRestraints(const AngleRestraints &other)
306-
: ConcreteProperty<AngleRestraints, Restraints>(other), r(other.r)
313+
: ConcreteProperty<AngleRestraints, Restraints>(other), r(other.r), use_pbc(other.use_pbc)
307314
{
308315
}
309316

@@ -318,14 +325,15 @@ AngleRestraints &AngleRestraints::operator=(const AngleRestraints &other)
318325
{
319326
Restraints::operator=(other);
320327
r = other.r;
328+
use_pbc = other.use_pbc;
321329
}
322330

323331
return *this;
324332
}
325333

326334
bool AngleRestraints::operator==(const AngleRestraints &other) const
327335
{
328-
return r == other.r and Restraints::operator==(other);
336+
return r == other.r and Restraints::operator==(other) and use_pbc == other.use_pbc;
329337
}
330338

331339
bool AngleRestraints::operator!=(const AngleRestraints &other) const
@@ -379,9 +387,10 @@ QString AngleRestraints::toString() const
379387
}
380388
}
381389

382-
return QObject::tr("AngleRestraints( name=%1, size=%2\n%3\n )")
390+
return QObject::tr("AngleRestraints( name=%1, size=%2, use_pbc=%3\n%4\n )")
383391
.arg(this->name())
384392
.arg(n)
393+
.arg(this->use_pbc ? "true" : "false")
385394
.arg(parts.join("\n"));
386395
}
387396

@@ -477,3 +486,15 @@ AngleRestraints AngleRestraints::operator+(const AngleRestraints &restraints) co
477486
ret += restraints;
478487
return *this;
479488
}
489+
490+
/** Set whether or not periodic boundary conditions are to be used */
491+
void AngleRestraints::setUsesPeriodicBoundaryConditions(bool use_pbc)
492+
{
493+
this->use_pbc = use_pbc;
494+
}
495+
496+
/** Return whether or not periodic boundary conditions are to be used */
497+
bool AngleRestraints::getUsesPeriodicBoundaryConditions() const
498+
{
499+
return this->use_pbc;
500+
}

‎corelib/src/libs/SireMM/anglerestraints.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,15 @@ namespace SireMM
161161
AngleRestraints operator+(const AngleRestraint &restraint) const;
162162
AngleRestraints operator+(const AngleRestraints &restraints) const;
163163

164+
void setUsesPeriodicBoundaryConditions(bool use_pbc);
165+
bool getUsesPeriodicBoundaryConditions() const;
166+
164167
private:
165168
/** List of restraints */
166169
QList<AngleRestraint> r;
170+
171+
/** Whether the restraints use periodic boundary conditions */
172+
bool use_pbc = false;
167173
};
168174
}
169175

‎corelib/src/libs/SireMM/bondrestraints.cpp‎

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,11 @@ static const RegisterMetaType<BondRestraints> r_bndrests;
350350

351351
QDataStream &operator<<(QDataStream &ds, const BondRestraints &bndrests)
352352
{
353-
writeHeader(ds, r_bndrests, 1);
353+
writeHeader(ds, r_bndrests, 2);
354354

355355
SharedDataStream sds(ds);
356356

357-
sds << bndrests.r
357+
sds << bndrests.r << bndrests.use_pbc
358358
<< static_cast<const Restraints &>(bndrests);
359359

360360
return ds;
@@ -370,8 +370,15 @@ QDataStream &operator>>(QDataStream &ds, BondRestraints &bndrests)
370370

371371
sds >> bndrests.r >> static_cast<Restraints &>(bndrests);
372372
}
373+
else if (v == 2)
374+
{
375+
SharedDataStream sds(ds);
376+
377+
sds >> bndrests.r >> bndrests.use_pbc
378+
>> static_cast<Restraints &>(bndrests);
379+
}
373380
else
374-
throw version_error(v, "1", r_bndrests, CODELOC);
381+
throw version_error(v, "1,2", r_bndrests, CODELOC);
375382

376383
return ds;
377384
}
@@ -435,13 +442,14 @@ BondRestraints::~BondRestraints()
435442
BondRestraints &BondRestraints::operator=(const BondRestraints &other)
436443
{
437444
r = other.r;
445+
use_pbc = other.use_pbc;
438446
Restraints::operator=(other);
439447
return *this;
440448
}
441449

442450
bool BondRestraints::operator==(const BondRestraints &other) const
443451
{
444-
return r == other.r and Restraints::operator==(other);
452+
return r == other.r and Restraints::operator==(other) and use_pbc == other.use_pbc;
445453
}
446454

447455
bool BondRestraints::operator!=(const BondRestraints &other) const
@@ -495,7 +503,11 @@ QString BondRestraints::toString() const
495503
}
496504
}
497505

498-
return QObject::tr("BondRestraints( name=%1, size=%2\n%3\n)").arg(this->name()).arg(n).arg(parts.join("\n"));
506+
return QObject::tr("BondRestraints( name=%1, size=%2, use_pbc=$3\n%4\n)")
507+
.arg(this->name())
508+
.arg(n)
509+
.arg(this->use_pbc ? "true" : "false")
510+
.arg(parts.join("\n"));
499511
}
500512

501513
/** Return whether or not this is empty */
@@ -678,3 +690,15 @@ BondRestraints BondRestraints::operator+(const BondRestraints &restraints) const
678690
ret += restraints;
679691
return *this;
680692
}
693+
694+
/** Set whether or not periodic boundary conditions are to be used */
695+
void BondRestraints::setUsesPeriodicBoundaryConditions(bool use_pbc)
696+
{
697+
this->use_pbc = use_pbc;
698+
}
699+
700+
/** Return whether or not periodic boundary conditions are to be used */
701+
bool BondRestraints::getUsesPeriodicBoundaryConditions() const
702+
{
703+
return this->use_pbc;
704+
}

‎corelib/src/libs/SireMM/bondrestraints.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,15 @@ namespace SireMM
191191
BondRestraints operator+(const BondRestraint &restraint) const;
192192
BondRestraints operator+(const BondRestraints &restraints) const;
193193

194+
void setUsesPeriodicBoundaryConditions(bool use_pbc);
195+
bool getUsesPeriodicBoundaryConditions() const;
196+
194197
private:
195198
/** The actual list of restraints*/
196199
QList<BondRestraint> r;
200+
201+
/** Whether the restraints use periodic boundary conditions */
202+
bool use_pbc = false;
197203
};
198204

199205
}

‎corelib/src/libs/SireMM/boreschrestraints.cpp‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,11 @@ static const RegisterMetaType<BoreschRestraints> r_borrests;
343343

344344
QDataStream &operator<<(QDataStream &ds, const BoreschRestraints &borrests)
345345
{
346-
writeHeader(ds, r_borrests, 1);
346+
writeHeader(ds, r_borrests, 2);
347347

348348
SharedDataStream sds(ds);
349349

350-
sds << borrests.r
350+
sds << borrests.r << borrests.use_pbc
351351
<< static_cast<const Restraints &>(borrests);
352352

353353
return ds;
@@ -363,8 +363,15 @@ QDataStream &operator>>(QDataStream &ds, BoreschRestraints &borrests)
363363

364364
sds >> borrests.r >> static_cast<Restraints &>(borrests);
365365
}
366+
else if (v == 2)
367+
{
368+
SharedDataStream sds(ds);
369+
370+
sds >> borrests.r >> borrests.use_pbc
371+
>> static_cast<Restraints &>(borrests);
372+
}
366373
else
367-
throw version_error(v, "1", r_borrests, CODELOC);
374+
throw version_error(v, "1,2", r_borrests, CODELOC);
368375

369376
return ds;
370377
}
@@ -417,7 +424,7 @@ BoreschRestraints::BoreschRestraints(const QString &name,
417424
}
418425

419426
BoreschRestraints::BoreschRestraints(const BoreschRestraints &other)
420-
: ConcreteProperty<BoreschRestraints, Restraints>(other), r(other.r)
427+
: ConcreteProperty<BoreschRestraints, Restraints>(other), r(other.r), use_pbc(other.use_pbc)
421428
{
422429
}
423430

@@ -428,13 +435,15 @@ BoreschRestraints::~BoreschRestraints()
428435
BoreschRestraints &BoreschRestraints::operator=(const BoreschRestraints &other)
429436
{
430437
r = other.r;
438+
use_pbc = other.use_pbc;
431439
Restraints::operator=(other);
432440
return *this;
433441
}
434442

435443
bool BoreschRestraints::operator==(const BoreschRestraints &other) const
436444
{
437-
return r == other.r and Restraints::operator==(other);
445+
return r == other.r and Restraints::operator==(other) and
446+
use_pbc == other.use_pbc;
438447
}
439448

440449
bool BoreschRestraints::operator!=(const BoreschRestraints &other) const
@@ -488,7 +497,11 @@ QString BoreschRestraints::toString() const
488497
}
489498
}
490499

491-
return QObject::tr("BoreschRestraints( name=%1, size=%2\n%3\n)").arg(this->name()).arg(n).arg(parts.join("\n"));
500+
return QObject::tr("BoreschRestraints( name=%1, size=%2, use_pbc=%3\n%4\n)")
501+
.arg(this->name())
502+
.arg(n)
503+
.arg(this->use_pbc ? "true" : "false")
504+
.arg(parts.join("\n"));
492505
}
493506

494507
/** Return whether or not this is empty */
@@ -583,3 +596,15 @@ BoreschRestraints BoreschRestraints::operator+(const BoreschRestraints &restrain
583596
ret += restraints;
584597
return *this;
585598
}
599+
600+
/** Set whether or not periodic boundary conditions are to be used */
601+
void BoreschRestraints::setUsesPeriodicBoundaryConditions(bool use_pbc)
602+
{
603+
this->use_pbc = use_pbc;
604+
}
605+
606+
/** Return whether or not periodic boundary conditions are to be used */
607+
bool BoreschRestraints::getUsesPeriodicBoundaryConditions() const
608+
{
609+
return this->use_pbc;
610+
}

‎corelib/src/libs/SireMM/boreschrestraints.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,15 @@ namespace SireMM
194194
BoreschRestraints operator+(const BoreschRestraint &restraint) const;
195195
BoreschRestraints operator+(const BoreschRestraints &restraints) const;
196196

197+
void setUsesPeriodicBoundaryConditions(bool use_pbc);
198+
bool getUsesPeriodicBoundaryConditions() const;
199+
197200
private:
198201
/** The actual list of restraints*/
199202
QList<BoreschRestraint> r;
203+
204+
/** Whether the restraints use periodic boundary conditions */
205+
bool use_pbc = false;
200206
};
201207

202208
}

‎corelib/src/libs/SireMM/dihedralrestraints.cpp‎

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,11 @@ static const RegisterMetaType<DihedralRestraints> r_dihrests;
225225

226226
QDataStream &operator<<(QDataStream &ds, const DihedralRestraints &dihrests)
227227
{
228-
writeHeader(ds, r_dihrests, 1);
228+
writeHeader(ds, r_dihrests, 2);
229229

230230
SharedDataStream sds(ds);
231231

232-
sds << dihrests.r
232+
sds << dihrests.r << dihrests.use_pbc
233233
<< static_cast<const Restraints &>(dihrests);
234234

235235
return ds;
@@ -247,8 +247,15 @@ QDataStream &operator>>(QDataStream &ds, DihedralRestraints &dihrests)
247247
sds >> dihrests.r >>
248248
static_cast<Restraints &>(dihrests);
249249
}
250+
else if (v == 2)
251+
{
252+
SharedDataStream sds(ds);
253+
254+
sds >> dihrests.r >> dihrests.use_pbc
255+
>> static_cast<Restraints &>(dihrests);
256+
}
250257
else
251-
throw version_error(v, "1", r_dihrests, CODELOC);
258+
throw version_error(v, "1,2", r_dihrests, CODELOC);
252259

253260
return ds;
254261
}
@@ -301,7 +308,7 @@ DihedralRestraints::DihedralRestraints(const QString &name,
301308
}
302309

303310
DihedralRestraints::DihedralRestraints(const DihedralRestraints &other)
304-
: ConcreteProperty<DihedralRestraints, Restraints>(other), r(other.r)
311+
: ConcreteProperty<DihedralRestraints, Restraints>(other), r(other.r), use_pbc(other.use_pbc)
305312
{
306313
}
307314

@@ -316,14 +323,16 @@ DihedralRestraints &DihedralRestraints::operator=(const DihedralRestraints &othe
316323
{
317324
Restraints::operator=(other);
318325
r = other.r;
326+
use_pbc = other.use_pbc;
319327
}
320328

321329
return *this;
322330
}
323331

324332
bool DihedralRestraints::operator==(const DihedralRestraints &other) const
325333
{
326-
return r == other.r and Restraints::operator==(other);
334+
return r == other.r and Restraints::operator==(other) and
335+
use_pbc == other.use_pbc;
327336
}
328337

329338
bool DihedralRestraints::operator!=(const DihedralRestraints &other) const
@@ -377,9 +386,10 @@ QString DihedralRestraints::toString() const
377386
}
378387
}
379388

380-
return QObject::tr("DihedralRestraints( name=%1, size=%2\n%3\n )")
389+
return QObject::tr("DihedralRestraints( name=%1, size=%2, use_pbc=%3\n%4\n )")
381390
.arg(this->name())
382391
.arg(n)
392+
.arg(this->use_pbc ? "true" : "false")
383393
.arg(parts.join("\n"));
384394
}
385395

@@ -474,4 +484,16 @@ DihedralRestraints DihedralRestraints::operator+(const DihedralRestraints &restr
474484
DihedralRestraints ret(*this);
475485
ret += restraints;
476486
return *this;
477-
}
487+
}
488+
489+
/** Set whether or not periodic boundary conditions are to be used */
490+
void DihedralRestraints::setUsesPeriodicBoundaryConditions(bool use_pbc)
491+
{
492+
this->use_pbc = use_pbc;
493+
}
494+
495+
/** Return whether or not periodic boundary conditions are to be used */
496+
bool DihedralRestraints::getUsesPeriodicBoundaryConditions() const
497+
{
498+
return this->use_pbc;
499+
}

0 commit comments

Comments
 (0)