Skip to content

Commit 440d29b

Browse files
committed
more on PD and PI
1 parent f4dd00a commit 440d29b

File tree

9 files changed

+311
-102
lines changed

9 files changed

+311
-102
lines changed

src/capabilities/confscan.cpp

Lines changed: 67 additions & 76 deletions
Large diffs are not rendered by default.

src/capabilities/confscan.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ static const json ConfScanJson = {
5656
{ "preventreorder", false },
5757
{ "scaleLoose", 1.5 },
5858
{ "scaleTight", 0.1 },
59-
{ "scaleLooseEnergy", 1.2 },
60-
{ "scaleTightEnergy", 0.1 },
61-
{ "scaleLooseRotational", 1.2 },
62-
{ "scaleTightRotational", 0.1 },
63-
{ "scaleLooseRipser", 1.2 },
64-
{ "scaleTightRipser", 0.1 },
59+
{ "sLE", 1.2 },
60+
{ "sTE", 0.1 },
61+
{ "sLI", 1.2 },
62+
{ "sTI", 0.1 },
63+
{ "sLH", 1.2 },
64+
{ "sTH", 0.1 },
6565
{ "skip", 0 },
6666
{ "allxyz", false },
6767
{ "update", false },
@@ -315,13 +315,13 @@ class ConfScan : public CurcumaMethod {
315315
std::map<double, int> m_ordered_list;
316316
std::vector<std::pair<std::string, Molecule*>> m_molecules;
317317
double m_rmsd_threshold = 1.0, m_nearly_missed = 0.8, m_energy_cutoff = -1, m_reference_last_energy = 0, m_target_last_energy = 0, m_lowest_energy = 1, m_current_energy = 0;
318-
double m_scaleTightEnergy = 0.1, m_scaleLooseEnergy = 1.5;
319-
double m_scaleTightRotational = 0.1, m_scaleLooseRotational = 1.5;
320-
double m_scaleTightRipser = 0.1, m_scaleLooseRipser = 1.5;
318+
double m_sTE = 0.1, m_sLE = 1.5;
319+
double m_sTI = 0.1, m_sLI = 1.5;
320+
double m_sTH = 0.1, m_sLH = 1.5;
321321

322322
double m_reference_restored_energy = -1e10, m_target_restored_energy = -1e10;
323-
double m_diff_rot_threshold_loose = 0.0, m_diff_ripser_threshold_loose = 0.0, m_diff_energy_threshold_loose = 0.0;
324-
double m_diff_rot_threshold_tight = 0.0, m_diff_ripser_threshold_tight = 0.0, m_diff_energy_threshold_tight = 0.0;
323+
double m_dLI = 0.0, m_dLH = 0.0, m_dLE = 0.0;
324+
double m_dTI = 0.0, m_dTH = 0.0, m_dTE = 0.0;
325325

326326
std::vector<Molecule*> m_result, m_rejected_structures, m_stored_structures, m_previously_accepted;
327327
std::vector<const Molecule*> m_threshold;
@@ -336,7 +336,7 @@ class ConfScan : public CurcumaMethod {
336336
std::string m_molalign = "molalign";
337337

338338
double m_domolalign = -1;
339-
double m_last_diff = 0.0, m_last_ripser = 0.0, m_last_dE = -1, m_dE = -1, m_damping = 0.8;
339+
double m_lastDI = 0.0, m_lastDH = 0.0, m_lastdE = -1, m_dE = -1, m_damping = 0.8;
340340
int m_maxmol = 0;
341341
int m_maxrank = 10000;
342342
int m_maxParam = -1;

src/capabilities/persistentdiagram.cpp

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
using json = nlohmann::json;
3131

32-
PersistentDiagram::PersistentDiagram(const json config)
32+
PersistentDiagram::PersistentDiagram(const json& config)
3333
{
3434
json j = MergeJson(RipserJson, config);
3535
// std::cout << j << std::endl;
@@ -43,13 +43,15 @@ PersistentDiagram::PersistentDiagram(const json config)
4343
m_std_x = j["ripser_stdx"];
4444
m_std_y = j["ripser_stdy"];
4545
m_dimension = j["ripser_dimension"];
46+
m_epsilon = j["ripser_epsilon"];
47+
4648
m_threshold = std::numeric_limits<float>::max();
4749
}
4850

4951
dpairs PersistentDiagram::generatePairs()
5052
{
5153
coefficient_t modulus = 2;
52-
54+
std::vector<float> distance = m_compressed_lower_distance_matrix;
5355
compressed_lower_distance_matrix dist(std::move(m_compressed_lower_distance_matrix));
5456

5557
value_t enclosing_radius = std::numeric_limits<value_t>::infinity();
@@ -75,6 +77,68 @@ dpairs PersistentDiagram::generatePairs()
7577
return final;
7678
}
7779

80+
triples PersistentDiagram::generateTriples()
81+
{
82+
coefficient_t modulus = 2;
83+
std::vector<float> distance = m_compressed_lower_distance_matrix;
84+
compressed_lower_distance_matrix dist(std::move(m_compressed_lower_distance_matrix));
85+
86+
value_t enclosing_radius = std::numeric_limits<value_t>::infinity();
87+
if (m_threshold == std::numeric_limits<value_t>::max()) {
88+
for (size_t i = 0; i < dist.size(); ++i) {
89+
value_t r_i = -std::numeric_limits<value_t>::infinity();
90+
for (size_t j = 0; j < dist.size(); ++j)
91+
r_i = std::max(r_i, dist(i, j));
92+
enclosing_radius = std::min(enclosing_radius, r_i);
93+
}
94+
}
95+
96+
auto result = ripser<compressed_lower_distance_matrix>(std::move(dist), m_dimension, enclosing_radius,
97+
m_ratio, modulus)
98+
.compute_barcodes();
99+
100+
triples final;
101+
for (const auto& a : result)
102+
if (a.first != 0) {
103+
for (const auto& b : a.second) {
104+
triple t;
105+
t.start = b.first;
106+
t.end = b.second;
107+
final.push_back(t);
108+
}
109+
} else {
110+
int counter = 0;
111+
std::vector<int> indices;
112+
for (const auto& b : a.second)
113+
114+
{
115+
bool found = false;
116+
for (int i = 0; i < distance.size(); ++i) {
117+
if (std::abs(distance[i] - b.second) < 1e-6 && std::find(indices.begin(), indices.end(), i) == indices.end()) {
118+
// std::cout << i << " " << distance[i] << " " << m_en_scaling[i] << " " << counter++ << std::endl;
119+
indices.push_back(i);
120+
triple t;
121+
t.start = b.first;
122+
t.end = b.second;
123+
t.scaling = m_en_scaling[i] + m_epsilon;
124+
final.push_back(t);
125+
126+
found = true;
127+
break;
128+
}
129+
}
130+
if (found == false) {
131+
triple t;
132+
t.start = b.first;
133+
t.end = b.second;
134+
final.push_back(t);
135+
}
136+
}
137+
}
138+
139+
return final;
140+
}
141+
78142
Eigen::MatrixXd PersistentDiagram::generateImage(const dpairs& pairs)
79143
{
80144
Eigen::MatrixXd matrix = Eigen::MatrixXd::Zero(m_bins, m_bins);
@@ -86,7 +150,6 @@ Eigen::MatrixXd PersistentDiagram::generateImage(const dpairs& pairs)
86150
for (int j = 0; j < matrix.rows(); ++j) // iteration over x values
87151
{
88152
double cur_x = (m_xmax - m_xmin) * i_bins * (j);
89-
90153
for (const auto& pair : pairs) {
91154
double x = pair.first;
92155
double y = pair.second;
@@ -96,3 +159,25 @@ Eigen::MatrixXd PersistentDiagram::generateImage(const dpairs& pairs)
96159
}
97160
return matrix;
98161
}
162+
163+
Eigen::MatrixXd PersistentDiagram::generateImage(const triples& pairs)
164+
{
165+
Eigen::MatrixXd matrix = Eigen::MatrixXd::Zero(m_bins, m_bins);
166+
167+
double i_bins = 1 / double(m_bins);
168+
for (int i = 0; i < matrix.cols(); ++i) // iteration over y values
169+
{
170+
double cur_y = m_ymax - (m_ymax - m_ymin) * i_bins * (i);
171+
for (int j = 0; j < matrix.rows(); ++j) // iteration over x values
172+
{
173+
double cur_x = (m_xmax - m_xmin) * i_bins * (j);
174+
for (const auto& triple : pairs) {
175+
double x = triple.start;
176+
double y = triple.end;
177+
double std = triple.scaling;
178+
matrix(i, j) += m_scaling * exp(-((cur_x - x) * (cur_x - x) * m_std_x / std)) * exp((-(cur_y - y) * (cur_y - y) * m_std_y / std));
179+
}
180+
}
181+
}
182+
return matrix;
183+
}

src/capabilities/persistentdiagram.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@
2626

2727
#include <Eigen/Dense>
2828

29+
struct triple {
30+
double start = 0;
31+
double end = 0;
32+
double scaling = 1;
33+
};
34+
2935
typedef std::pair<double, double> dpair;
3036

3137
typedef std::vector<dpair> dpairs;
38+
typedef std::vector<triple> triples;
39+
3240
using json = nlohmann::json;
3341

3442
static const json RipserJson = {
@@ -41,18 +49,24 @@ static const json RipserJson = {
4149
{ "ripser_stdx", 10 },
4250
{ "ripser_stdy", 10 },
4351
{ "ripser_ratio", 1 },
44-
{ "ripser_dimension", 2 }
52+
{ "ripser_dimension", 2 },
53+
{ "ripser_epsilon", 0.4 }
4554
};
4655

4756
class PersistentDiagram {
4857
public:
49-
PersistentDiagram(const json config = RipserJson);
58+
PersistentDiagram(const json& config = RipserJson);
5059

5160
inline void setDistanceMatrix(const std::vector<float>& vector)
5261
{
5362
m_compressed_lower_distance_matrix = vector;
5463
}
5564

65+
inline void setENScaling(const std::vector<double>& en_scaling)
66+
{
67+
m_en_scaling = en_scaling;
68+
}
69+
5670
inline void setDimension(int dim)
5771
{
5872
m_dimension = dim;
@@ -69,6 +83,7 @@ class PersistentDiagram {
6983
}
7084

7185
dpairs generatePairs();
86+
triples generateTriples();
7287

7388
inline void setXRange(double xmin, double xmax)
7489
{
@@ -83,6 +98,7 @@ class PersistentDiagram {
8398
}
8499

85100
Eigen::MatrixXd generateImage(const dpairs& pairs);
101+
Eigen::MatrixXd generateImage(const triples& pairs);
86102

87103
void setScaling(double scaling) { m_scaling = scaling; }
88104
void setBins(int bins) { m_bins = bins; }
@@ -98,5 +114,7 @@ class PersistentDiagram {
98114
double m_scaling = 0.1;
99115
double m_std_x = 10;
100116
double m_std_y = 10;
117+
double m_epsilon = 0.4;
101118
std::vector<float> m_compressed_lower_distance_matrix;
119+
std::vector<double> m_en_scaling;
102120
};

src/core/elements.h

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,95 @@ static const std::vector<double> CovalentRadius = {
486486
1.46 // At - taken from Bi
487487
};
488488

489+
static const std::vector<double> PaulingEN = {
490+
-1, // leading index
491+
2.2, // H
492+
0, // He
493+
0.98, // Li
494+
1.57, // Be
495+
2.04, // B
496+
2.55, // C
497+
3.04, // N
498+
3.44, // O
499+
3.98, // F
500+
0, // Ne
501+
0.93, // Na
502+
1.31, // Mg
503+
1.61, // Al
504+
1.9, // S
505+
2.19, // P
506+
2.58, // S
507+
3.16, // Cl
508+
0, // Ar
509+
0.82, // K
510+
1.0, // Ca
511+
1.36, // Sc
512+
1.54, // Ti
513+
1.63, // V
514+
1.66, // Cr
515+
1.55, // Mn
516+
1.83, // Fe
517+
1.88, // Co
518+
1.91, // Ni
519+
1.9, // Cu
520+
1.65, // Zn
521+
1.81, // Ga
522+
2.01, // Ge
523+
2.18, // As
524+
2.55, // Se
525+
2.96, // Br
526+
0, // Kr
527+
0.82, // Rb
528+
0.95, // Sr
529+
1.22, // Y
530+
1.33, // Zr
531+
1.6, // Nb
532+
2.16, // Mo
533+
1.9, // Tc
534+
2.2, // Ru
535+
2.28, // Rh
536+
2.20, // Pd
537+
1.93, // Ag
538+
1.69, // Cd
539+
1.78, // In
540+
1.96, // Sn
541+
2.05, // Sb
542+
2.1, // Te
543+
2.66, // I
544+
0, // Xe
545+
0.79, // Cs
546+
0.89, // Ba
547+
1.1, // La
548+
1.12, // Ce - taken from La
549+
1.13, // Pr - taken from La
550+
1.14, // Nd - taken from La
551+
1.13, // Pm - taken from La
552+
1.17, // Sm - taken from La
553+
1.2, // Eu - taken from La
554+
1.2, // Gd - taken from La
555+
1.2, // Tb - taken from La
556+
1.22, // Dy - taken from La
557+
1.23, // Ho - taken from La
558+
1.24, // Er - taken from La
559+
1.25, // Tm - taken from La
560+
1.1, // Yb - taken from La
561+
1.27, // Lu
562+
1.3, // Hf
563+
1.5, // Ta
564+
2.36, // W
565+
1.9, // Re
566+
2.2, // Os
567+
2.2, // Ir
568+
2.28, // Pt
569+
2.54, // Au
570+
2, // Hg
571+
2.04, // Tl
572+
2.33, // Pb
573+
2.02, // Bi
574+
2.0, // Po - taken from Bi
575+
2.2 // At - taken from Bi
576+
};
577+
489578
// The old ones
490579
/* for now, taken from here
491580
* https://de.wikipedia.org/wiki/Van-der-Waals-Radius */

src/core/molecule.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,17 @@ std::vector<float> Molecule::LowerDistanceVector() const
769769
return vector;
770770
}
771771

772+
std::vector<double> Molecule::DeltaEN() const
773+
{
774+
std::vector<double> vector;
775+
for (int i = 0; i < AtomCount(); ++i) {
776+
for (int j = 0; j < i; ++j) {
777+
vector.push_back(std::abs(Elements::PaulingEN[m_atoms[i]] - Elements::PaulingEN[m_atoms[j]]));
778+
}
779+
}
780+
return vector;
781+
}
782+
772783
Position Molecule::Centroid(bool protons, int fragment) const
773784
{
774785
return GeometryTools::Centroid(getGeometryByFragment(fragment, protons));

src/core/molecule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class Molecule
101101

102102
std::string LowerDistanceMatrix() const;
103103
std::vector<float> LowerDistanceVector() const;
104+
std::vector<double> DeltaEN() const;
104105

105106
bool setGeometry(const Geometry &geometry);
106107
bool setGeometryByFragment(const Geometry& geometry, int fragment, bool protons = true);

0 commit comments

Comments
 (0)