Skip to content

Commit ecb14ad

Browse files
author
Roberto Di Remigio
committed
Added cavity constructor from single sphere
1 parent 0ce0617 commit ecb14ad

File tree

5 files changed

+182
-119
lines changed

5 files changed

+182
-119
lines changed

src/cavity/Cavity.cpp

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,39 @@
2525

2626
#include "Cavity.hpp"
2727

28-
#include <iomanip>
2928
#include <iostream>
30-
#include <fstream>
31-
#include <limits>
3229

3330
#include "Config.hpp"
3431

3532
#include <Eigen/Core>
36-
#include "utils/cnpy.hpp"
3733

34+
#include "utils/cnpy.hpp"
3835
#include "utils/MathUtils.hpp"
36+
#include "utils/Sphere.hpp"
3937
#include "utils/Symmetry.hpp"
4038

39+
Cavity::Cavity() : nElements_(0), built(false) {}
40+
41+
Cavity::Cavity(const Sphere & sph) : built(false) {
42+
spheres_.push_back(sph);
43+
molecule_ = Molecule(spheres_);
44+
nSpheres_ = spheres_.size();
45+
transfer_spheres(spheres_, sphereCenter_, sphereRadius_);
46+
}
47+
48+
Cavity::Cavity(const std::vector<Sphere> & sph) : spheres_(sph), built(false) {
49+
molecule_ = Molecule(spheres_);
50+
nSpheres_ = spheres_.size();
51+
transfer_spheres(spheres_, sphereCenter_, sphereRadius_);
52+
}
53+
54+
Cavity::Cavity(const Molecule & molec) : spheres_(molec.spheres()), molecule_(molec), built(false) {
55+
nSpheres_ = spheres_.size();
56+
transfer_spheres(spheres_, sphereCenter_, sphereRadius_);
57+
}
58+
4159
void Cavity::saveCavity(const std::string & fname)
4260
{
43-
/*
44-
std::ofstream weights("weights.txt", std::ios_base::out);
45-
// First line in the weights file is the number of elements.
46-
// This is for a sanity-check on the save/load operations.
47-
weights << std::setprecision(std::numeric_limits<double>::digits10) << nElements_ << std::endl;
48-
weights << std::setprecision(std::numeric_limits<double>::digits10) << elementArea_ << std::endl;
49-
std::ofstream elRadius("element_radius.txt", std::ios_base::out);
50-
elRadius << std::setprecision(std::numeric_limits<double>::digits10) << elementRadius_ << std::endl;
51-
std::ofstream centers("centers.txt", std::ios_base::out);
52-
centers << std::setprecision(std::numeric_limits<double>::digits10) << elementCenter_ << std::endl;
53-
std::ofstream normals("normals.txt", std::ios_base::out);
54-
normals << std::setprecision(std::numeric_limits<double>::digits10) << elementNormal_ << std::endl;
55-
*/
56-
5761
// Write everything in a single .npz binary file
5862
unsigned int dim = static_cast<unsigned int>(nElements_);
5963
// Write the number of elements, it will be used to check sanity of the save/load operations.

src/cavity/Cavity.hpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
#include "cavity/Element.hpp"
3737
#include "utils/Molecule.hpp"
38-
#include "utils/Sphere.hpp"
3938
#include "utils/Symmetry.hpp"
4039

4140
/*!
@@ -91,24 +90,23 @@ class Cavity
9190
virtual std::ostream & printCavity(std::ostream & os) = 0;
9291
public:
9392
//! Default constructor
94-
Cavity() : nElements_(0), built(false) {}
93+
Cavity();
94+
/*! \brief Constructor from a single sphere
95+
* \param[in] sph the sphere
96+
*
97+
* Only used when we have to deal with a single sphere, i.e. in the unit tests
98+
*/
99+
Cavity(const Sphere & sph);
95100
/*! \brief Constructor from list of spheres
96101
* \param[in] sph the list of spheres
97102
*
98103
* Only used when we have to deal with a single sphere, i.e. in the unit tests
99104
*/
100-
Cavity(const std::vector<Sphere> & sph) : spheres_(sph), built(false) {
101-
molecule_ = Molecule(spheres_);
102-
nSpheres_ = spheres_.size();
103-
transfer_spheres(spheres_, sphereCenter_, sphereRadius_);
104-
}
105+
Cavity(const std::vector<Sphere> & sph);
105106
/*! \brief Constructor from Molecule
106107
* \param[in] molec the molecular aggregate
107108
*/
108-
Cavity(const Molecule & molec) : spheres_(molec.spheres()), molecule_(molec), built(false) {
109-
nSpheres_ = spheres_.size();
110-
transfer_spheres(spheres_, sphereCenter_, sphereRadius_);
111-
}
109+
Cavity(const Molecule & molec);
112110
virtual ~Cavity() {}
113111
Eigen::Matrix3Xd & elementCenter() { return elementCenter_; }
114112
const Eigen::Matrix3Xd & elementCenter() const { return elementCenter_; }

src/cavity/GePolCavity.cpp

Lines changed: 23 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <algorithm>
2929
#include <cctype>
3030
#include <fstream>
31-
#include <iomanip>
3231
#include <iostream>
3332
#include <sstream>
3433
#include <string>
@@ -43,53 +42,29 @@
4342
#include "utils/Sphere.hpp"
4443
#include "utils/Symmetry.hpp"
4544

46-
/*! \fn extern "C" void generatecavity_cpp(int * maxts, int * maxsph, int * maxvert,
47-
* double * xtscor, double * ytscor, double * ztscor, double * ar,
48-
* double * xsphcor, double * ysphcor, double * zsphcor, double * rsph,
49-
* int * nts, int * ntsirr, int * nesfp, int * addsph,
50-
* double * xe, double * ye, double * ze, double * rin,
51-
* double * avgArea, double * rsolv, double * ret,
52-
* int * nr_gen, int * gen1, int * gen2, int * gen3,
53-
* int * nvert, double * vert, double * centr)
54-
* \param[in] maxts maximum number of tesserae allowed
55-
* \param[in] maxsph maximum number of spheres allowed
56-
* \param[in] maxvert maximum number of vertices allowed
57-
* \param[out] xtscor x-coordinate of tesserae centers (dimension maxts)
58-
* \param[out] ytscor y-coordinate of tesserae centers (dimension maxts)
59-
* \param[out] ztscor z-coordinate of tesserae centers (dimension maxts)
60-
* \param[out] ar area of the tessera (dimension maxts)
61-
* \param[out] xsphcor x-coordinate of the sphere center the tessera belongs to (dimension maxts)
62-
* \param[out] ysphcor y-coordinate of the sphere center the tessera belongs to (dimension maxts)
63-
* \param[out] zsphcor z-coordinate of the sphere center the tessera belongs to (dimension maxts)
64-
* \param[out] rsph radii of the sphere the tessera belongs to, i.e. its curvature (dimension maxts)
65-
* \param[out] nts number of generated tesserae
66-
* \param[out] ntsirr number of generated irreducible tesserae
67-
* \param[out] nesfp number of spheres (original + added)
68-
* \param[out] addsph number of added spheres
69-
* \param[out] xe x-coordinate of the sphere center (dimension nSpheres_ + maxAddedSpheres)
70-
* \param[out] ye y-coordinate of the sphere center (dimension nSpheres_ + maxAddedSpheres)
71-
* \param[out] ze z-coordinate of the sphere center (dimension nSpheres_ + maxAddedSpheres)
72-
* \param[out] rin radius of the spheres (dimension nSpheres_ + maxAddedSpheres)
73-
* \param[in] masses atomic masses (for inertia tensor formation in PEDRA)
74-
* \param[in] avgArea average tesserae area
75-
* \param[in] rsolv solvent probe radius
76-
* \param[in] ret minimal radius for an added sphere
77-
* \param[in] nr_gen number of symmetry generators
78-
* \param[in] gen1 first generator
79-
* \param[in] gen2 second generator
80-
* \param[in] gen3 third generator
81-
* \param[out] nvert number of vertices per tessera
82-
* \param[out] vert coordinates of tesserae vertices
83-
* \param[out] centr centers of arcs defining the edges of the tesserae
84-
*/
85-
extern "C" void generatecavity_cpp(int * maxts, int * maxsph, int * maxvert,
86-
double * xtscor, double * ytscor, double * ztscor, double * ar,
87-
double * xsphcor, double * ysphcor, double * zsphcor, double * rsph,
88-
int * nts, int * ntsirr, int * nesfp, int * addsph,
89-
double * xe, double * ye, double * ze, double * rin, double * masses,
90-
double * avgArea, double * rsolv, double * ret,
91-
int * nr_gen, int * gen1, int * gen2, int * gen3,
92-
int * nvert, double * vert, double * centr, int * isphe, const char * pedra, int * len_f_pedra);
45+
GePolCavity::GePolCavity(const Molecule & molec, double a, double pr, double minR, const std::string & suffix) :
46+
Cavity(molec), averageArea(a), probeRadius(pr), minimalRadius(minR)
47+
{
48+
TIMER_ON("GePolCavity::build from Molecule object");
49+
build(suffix, 10000, 200, 25000);
50+
TIMER_OFF("GePolCavity::build from Molecule object");
51+
}
52+
53+
GePolCavity::GePolCavity(const Sphere & sph, double a, double pr, double minR, const std::string & suffix) :
54+
Cavity(sph), averageArea(a), probeRadius(pr), minimalRadius(minR)
55+
{
56+
TIMER_ON("GePolCavity::build from single sphere");
57+
build(suffix, 10000, 200, 25000);
58+
TIMER_OFF("GePolCavity::build from single sphere");
59+
}
60+
61+
GePolCavity::GePolCavity(const std::vector<Sphere> & sph, double a, double pr, double minR, const std::string & suffix) :
62+
Cavity(sph), averageArea(a), probeRadius(pr), minimalRadius(minR)
63+
{
64+
TIMER_ON("GePolCavity::build from list of spheres");
65+
build(suffix, 10000, 200, 25000);
66+
TIMER_OFF("GePolCavity::build from list of spheres");
67+
}
9368

9469
void GePolCavity::build(const std::string & suffix, int maxts, int maxsph, int maxvert)
9570
{

src/cavity/GePolCavity.hpp

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@
3232

3333
#include "Config.hpp"
3434

35-
#include <boost/current_function.hpp>
36-
3735
#include "Cavity.hpp"
3836

3937
/*! \file GePolCavity.hpp
4038
* \class GePolCavity
4139
* \brief A class for GePol cavity.
42-
* \author Krzysztof Mozgawa
43-
* \date 2011
40+
* \author Krzysztof Mozgawa, Roberto Di Remigio
41+
* \date 2011, 2016
4442
*
4543
* This class is an interface to the Fortran code PEDRA for the generation
4644
* of cavities according to the GePol algorithm.
@@ -50,22 +48,9 @@ class GePolCavity __final : public Cavity
5048
{
5149
public:
5250
GePolCavity() {}
53-
GePolCavity(const Molecule & molec, double a, double pr, double minR, const std::string & suffix = "") :
54-
Cavity(molec), averageArea(a), probeRadius(pr), minimalRadius(minR)
55-
{
56-
std::string checkpointName = "GePolCavity::build";
57-
TIMER_ON(checkpointName);
58-
build(suffix, 10000, 200, 25000);
59-
TIMER_OFF(checkpointName);
60-
}
61-
GePolCavity(const std::vector<Sphere> & sph, double a, double pr, double minR, const std::string & suffix = "") :
62-
Cavity(sph), averageArea(a), probeRadius(pr), minimalRadius(minR)
63-
{
64-
std::string checkpointName = "GePolCavity::build";
65-
TIMER_ON(checkpointName);
66-
build(suffix, 10000, 200, 25000);
67-
TIMER_OFF(checkpointName);
68-
}
51+
GePolCavity(const Molecule & molec, double a, double pr, double minR, const std::string & suffix = "");
52+
GePolCavity(const Sphere & sph, double a, double pr, double minR, const std::string & suffix = "");
53+
GePolCavity(const std::vector<Sphere> & sph, double a, double pr, double minR, const std::string & suffix = "");
6954
virtual ~GePolCavity() {}
7055
friend std::ostream & operator<<(std::ostream & os, GePolCavity & cavity) {
7156
return cavity.printCavity(os);
@@ -91,4 +76,52 @@ class GePolCavity __final : public Cavity
9176
void writeOFF(const std::string & suffix);
9277
};
9378

79+
/*! \fn extern "C" void generatecavity_cpp(int * maxts, int * maxsph, int * maxvert,
80+
* double * xtscor, double * ytscor, double * ztscor, double * ar,
81+
* double * xsphcor, double * ysphcor, double * zsphcor, double * rsph,
82+
* int * nts, int * ntsirr, int * nesfp, int * addsph,
83+
* double * xe, double * ye, double * ze, double * rin,
84+
* double * avgArea, double * rsolv, double * ret,
85+
* int * nr_gen, int * gen1, int * gen2, int * gen3,
86+
* int * nvert, double * vert, double * centr)
87+
* \param[in] maxts maximum number of tesserae allowed
88+
* \param[in] maxsph maximum number of spheres allowed
89+
* \param[in] maxvert maximum number of vertices allowed
90+
* \param[out] xtscor x-coordinate of tesserae centers (dimension maxts)
91+
* \param[out] ytscor y-coordinate of tesserae centers (dimension maxts)
92+
* \param[out] ztscor z-coordinate of tesserae centers (dimension maxts)
93+
* \param[out] ar area of the tessera (dimension maxts)
94+
* \param[out] xsphcor x-coordinate of the sphere center the tessera belongs to (dimension maxts)
95+
* \param[out] ysphcor y-coordinate of the sphere center the tessera belongs to (dimension maxts)
96+
* \param[out] zsphcor z-coordinate of the sphere center the tessera belongs to (dimension maxts)
97+
* \param[out] rsph radii of the sphere the tessera belongs to, i.e. its curvature (dimension maxts)
98+
* \param[out] nts number of generated tesserae
99+
* \param[out] ntsirr number of generated irreducible tesserae
100+
* \param[out] nesfp number of spheres (original + added)
101+
* \param[out] addsph number of added spheres
102+
* \param[out] xe x-coordinate of the sphere center (dimension nSpheres_ + maxAddedSpheres)
103+
* \param[out] ye y-coordinate of the sphere center (dimension nSpheres_ + maxAddedSpheres)
104+
* \param[out] ze z-coordinate of the sphere center (dimension nSpheres_ + maxAddedSpheres)
105+
* \param[out] rin radius of the spheres (dimension nSpheres_ + maxAddedSpheres)
106+
* \param[in] masses atomic masses (for inertia tensor formation in PEDRA)
107+
* \param[in] avgArea average tesserae area
108+
* \param[in] rsolv solvent probe radius
109+
* \param[in] ret minimal radius for an added sphere
110+
* \param[in] nr_gen number of symmetry generators
111+
* \param[in] gen1 first generator
112+
* \param[in] gen2 second generator
113+
* \param[in] gen3 third generator
114+
* \param[out] nvert number of vertices per tessera
115+
* \param[out] vert coordinates of tesserae vertices
116+
* \param[out] centr centers of arcs defining the edges of the tesserae
117+
*/
118+
extern "C" void generatecavity_cpp(int * maxts, int * maxsph, int * maxvert,
119+
double * xtscor, double * ytscor, double * ztscor, double * ar,
120+
double * xsphcor, double * ysphcor, double * zsphcor, double * rsph,
121+
int * nts, int * ntsirr, int * nesfp, int * addsph,
122+
double * xe, double * ye, double * ze, double * rin, double * masses,
123+
double * avgArea, double * rsolv, double * ret,
124+
int * nr_gen, int * gen1, int * gen2, int * gen3,
125+
int * nvert, double * vert, double * centr, int * isphe, const char * pedra, int * len_f_pedra);
126+
94127
#endif // GEPOLCAVITY_HPP

0 commit comments

Comments
 (0)