-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathConfigIO.cc
More file actions
1359 lines (1190 loc) · 50.2 KB
/
ConfigIO.cc
File metadata and controls
1359 lines (1190 loc) · 50.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "casm/clex/ConfigIO.hh"
#include <functional>
#include "casm/app/ClexDescription.hh"
#include "casm/app/ProjectSettings.hh"
#include "casm/casm_io/Log.hh"
#include "casm/casm_io/container/json_io.hh"
#include "casm/casm_io/dataformatter/DataFormatterTools_impl.hh"
#include "casm/casm_io/dataformatter/DataFormatter_impl.hh"
#include "casm/casm_io/json/jsonParser.hh"
#include "casm/clex/Calculable.hh"
#include "casm/clex/ClexBasisSpecs.hh"
#include "casm/clex/ConfigCorrelations.hh"
#include "casm/clex/ConfigIOHull.hh"
#include "casm/clex/ConfigIOLocalCorr.hh"
#include "casm/clex/ConfigIONovelty.hh"
#include "casm/clex/ConfigIOStrain.hh"
#include "casm/clex/ConfigIOStrucScore.hh"
#include "casm/clex/ConfigMapping.hh"
#include "casm/clex/MappedProperties.hh"
#include "casm/clex/NeighborhoodInfo.hh"
#include "casm/clex/Norm.hh"
#include "casm/clex/PrimClex.hh"
#include "casm/clex/SimpleStructureTools.hh"
#include "casm/clex/io/json/Configuration_json_io.hh"
#include "casm/clex/io/stream/Configuration_stream_io.hh"
#include "casm/crystallography/BasicStructureTools.hh"
#include "casm/crystallography/SimpleStructure.hh"
#include "casm/crystallography/Structure.hh"
#include "casm/crystallography/io/SimpleStructureIO.hh"
#include "casm/crystallography/io/UnitCellCoordIO.hh"
#include "casm/crystallography/io/VaspIO.hh"
#include "casm/database/ConfigDatabase.hh"
#include "casm/database/PropertiesDatabase.hh"
#include "casm/database/Selected.hh"
namespace CASM {
template class BaseDatumFormatter<Configuration>;
template class DataFormatterOperator<bool, std::string, Configuration>;
template class DataFormatterOperator<bool, bool, Configuration>;
template class DataFormatterOperator<bool, double, Configuration>;
template class DataFormatterOperator<double, double, Configuration>;
template class DataFormatterOperator<Index, double, Configuration>;
template class DataFormatter<Configuration>;
template bool DataFormatter<Configuration>::evaluate_as_scalar<bool>(
Configuration const &) const;
template double DataFormatter<Configuration>::evaluate_as_scalar<double>(
Configuration const &) const;
template class DataFormatterDictionary<Configuration>;
namespace ConfigIO_impl {
/// \brief Expects arguments of the form 'name' or 'name(Au)', 'name(Pt)', etc.
bool MolDependent::parse_args(const std::string &args) {
if (args.size() > 0) m_mol_names.push_back(args);
return true;
}
/// \brief Adds index rules corresponding to the parsed args
bool MolDependent::init(const Configuration &_tmplt) const {
auto struc_mol = xtal::struc_molecule_name(_tmplt.primclex().prim());
if (m_mol_names.size() == 0) {
for (Index i = 0; i < struc_mol.size(); i++) {
_add_rule(std::vector<Index>({i}));
m_mol_names.push_back(struc_mol[i]);
}
} else {
for (Index n = 0; n < m_mol_names.size(); n++) {
Index i = 0;
for (i = 0; i < struc_mol.size(); i++) {
if (struc_mol[i] == m_mol_names[n]) {
_add_rule(std::vector<Index>({i}));
break;
}
}
if (i == struc_mol.size())
throw std::runtime_error(
std::string("Format tag: '") + name() + "(" + m_mol_names[n] +
")' does not correspond to a viable composition.\n");
}
}
return true;
}
/// \brief col_header returns: {'name(Au)', 'name(Pt)', ...}
std::vector<std::string> MolDependent::col_header(
const Configuration &_tmplt) const {
std::vector<std::string> col;
for (Index c = 0; c < m_mol_names.size(); c++) {
col.push_back(name() + "(" + m_mol_names[c] + ")");
}
return col;
}
} // namespace ConfigIO_impl
namespace ConfigIO {
// --- Comp implementations -----------
const std::string Comp::Name = "comp";
const std::string Comp::Desc =
"Parametric composition parameters, individual label as argument. "
"Without argument, all values are printed. Ex: comp(a), comp(b), etc.";
/// \brief Returns the parametric composition
Eigen::VectorXd Comp::evaluate(const Configuration &config) const {
return comp(config);
}
/// \brief Returns true if the PrimClex has composition axes
bool Comp::validate(const Configuration &config) const {
return config.primclex().has_composition_axes();
}
/// \brief Expects arguments of the form 'comp(a)', 'comp(b)', etc.
bool Comp::parse_args(const std::string &args) {
if (args.size() == 1) {
_add_rule(std::vector<Index>({(Index)(args[0] - 'a')}));
} else if (args.size() > 1) {
throw std::runtime_error(std::string("Format tag: 'comp(") + args +
") is invalid.\n");
return false;
}
return true;
}
/// \brief col_header returns: {'comp(a)', 'comp(b)', ...}
std::vector<std::string> Comp::col_header(const Configuration &_tmplt) const {
std::vector<std::string> col;
for (Index c = 0; c < _index_rules().size(); c++) {
col.push_back(name() + "(" + (char)('a' + _index_rules()[c][0]) + ")");
}
return col;
}
// --- CompN implementations -----------
const std::string CompN::Name = "comp_n";
const std::string CompN::Desc =
"Number of each species per unit cell, including vacancies. "
"No argument prints all available values. Ex: comp_n, comp_n(Au), "
"comp_n(Pt), etc.";
/// \brief Returns the number of each species per unit cell
Eigen::VectorXd CompN::evaluate(const Configuration &config) const {
return comp_n(config);
}
// --- SiteFrac implementations -----------
const std::string SiteFrac::Name = "site_frac";
const std::string SiteFrac::Desc =
"Fraction of sites occupied by a species, including vacancies. "
"No argument prints all available values. Ex: site_frac(Au), "
"site_frac(Pt), etc.";
/// \brief Returns the site fraction
Eigen::VectorXd SiteFrac::evaluate(const Configuration &config) const {
return site_frac(config);
}
// --- AtomFrac implementations -----------
const std::string AtomFrac::Name = "atom_frac";
const std::string AtomFrac::Desc =
"Fraction of atoms that are a particular species, excluding vacancies. "
"Without argument, all values are printed. Ex: atom_frac(Au), "
"atom_frac(Pt), etc.";
/// \brief Returns the site fraction
Eigen::VectorXd AtomFrac::evaluate(const Configuration &config) const {
return species_frac(config);
}
// --- Corr implementations -----------
const std::string Corr::Name = "corr";
const std::string Corr::Desc =
"Correlation values (evaluated basis functions, normalized per primitive "
"cell). "
"If no arguments, prints all correlations, using the basis set for the "
"default "
"cluster expansion as listed by 'casm settings -l'. "
"If one argument, accepts either: "
"1) a cluster expansion name, for example 'corr(formation_energy)', and "
"evaluates all basis functions, or "
"2) an integer index or range of indices of basis functions to evaluate, "
"for example 'corr(6)', or 'corr(0:6)'. "
"If two arguments, accepts cluster expansion name and an integer index or "
"range of basis functions to evaluate, for example "
"'corr(formation_energy,6)' "
"or 'corr(formation_energy,0:6)'.";
/// \brief Returns the atom fraction
Eigen::VectorXd Corr::evaluate(const Configuration &config) const {
Eigen::VectorXd corr;
restricted_extensive_correlations(
corr, config.configdof(), config.supercell().nlist(), m_clexulator,
m_correlation_indices.data(), end_ptr(m_correlation_indices));
corr /= ((double)config.supercell().volume());
return corr;
}
/// \brief If not yet initialized, use the default clexulator from the PrimClex
bool Corr::init(const Configuration &_tmplt) const {
if (!m_clexulator.initialized()) {
const PrimClex &primclex = _tmplt.primclex();
ClexDescription desc = m_clex_name.empty()
? primclex.settings().default_clex()
: primclex.settings().clex(m_clex_name);
m_clexulator = primclex.clexulator(desc.bset);
}
VectorXdAttribute<Configuration>::init(_tmplt);
m_correlation_indices.clear();
for (Index i = 0; i < _index_rules().size(); i++) {
m_correlation_indices.push_back(_index_rules()[i][0]);
}
return true;
}
/// \brief Expects 'corr', 'corr(clex_name)', 'corr(index_expression)', or
/// 'corr(clex_name,index_expression)'
bool Corr::parse_args(const std::string &args) {
std::vector<std::string> splt_vec;
boost::split(splt_vec, args, boost::is_any_of(","), boost::token_compress_on);
if (!splt_vec.size()) {
return true;
} else if (splt_vec.size() == 1) {
if ((splt_vec[0].find_first_not_of("0123456789") == std::string::npos) ||
(splt_vec[0].find(':') != std::string::npos)) {
_parse_index_expression(splt_vec[0]);
} else {
m_clex_name = splt_vec[0];
}
} else if (splt_vec.size() == 2) {
m_clex_name = splt_vec[0];
_parse_index_expression(splt_vec[1]);
} else {
std::stringstream ss;
ss << "Too many arguments for 'corr'. Received: " << args << "\n";
throw std::runtime_error(ss.str());
}
return true;
}
// --- CorrContribution implementations -----------
const std::string CorrContribution::Name = "corr_contribution";
const std::string CorrContribution::Desc =
"Correlation values (evaluated basis functions for a single unit cell, not "
" normalized). The first argument is the linear unit cell index [0, "
" scel_vol). The remaining arguments follow the same conventions as "
"`corr` accepting any of `corr_contribution(linear_unitcell_index)` or "
"`corr_contribution(linear_unitcell_index, clex_name)` or "
"`corr_contribution(linear_unitcell_index, indices)`, or "
"`corr_contribution(linear_unitcell_index, clex_name, indices)`. "
"Coordinates of unit cells can be obtained from the `unitcells` "
"information of the `info -m SupercellInfo` command.";
/// \brief Returns the atom fraction
Eigen::VectorXd CorrContribution::evaluate(const Configuration &config) const {
return corr_contribution(m_linear_unitcell_index, config, m_clexulator);
}
/// \brief If not yet initialized, use the default clexulator from the PrimClex
bool CorrContribution::init(const Configuration &_tmplt) const {
if (!m_clexulator.initialized()) {
const PrimClex &primclex = _tmplt.primclex();
ClexDescription desc = m_clex_name.empty()
? primclex.settings().default_clex()
: primclex.settings().clex(m_clex_name);
m_clexulator = primclex.clexulator(desc.bset);
}
VectorXdAttribute<Configuration>::init(_tmplt);
return true;
}
///
/// Expects one of:
/// - 'corr_contribution(linear_unitcell_index)'
/// - 'corr(linear_unitcell_index), clex_name)'
/// - 'corr(linear_unitcell_index, index_expression)'
/// - 'corr(clex_name,index_expression)'
bool CorrContribution::parse_args(const std::string &args) {
std::vector<std::string> splt_vec;
boost::split(splt_vec, args, boost::is_any_of(","), boost::token_compress_on);
if (!splt_vec.size()) {
return false;
}
if (splt_vec.size() == 1) {
m_linear_unitcell_index = std::stol(splt_vec[0]);
} else if (splt_vec.size() == 2) {
m_linear_unitcell_index = std::stol(splt_vec[0]);
if ((splt_vec[1].find_first_not_of("0123456789") == std::string::npos) ||
(splt_vec[1].find(':') != std::string::npos)) {
_parse_index_expression(splt_vec[1]);
} else {
m_clex_name = splt_vec[1];
}
} else if (splt_vec.size() == 3) {
m_linear_unitcell_index = std::stol(splt_vec[0]);
m_clex_name = splt_vec[1];
_parse_index_expression(splt_vec[2]);
} else {
std::stringstream ss;
ss << "Too many arguments for 'corr_contribution'. Received: " << args
<< "\n";
throw std::runtime_error(ss.str());
}
return true;
}
// --- PointCorr implementations -----------
const std::string PointCorr::Name = "point_corr";
const std::string PointCorr::Desc =
"Point correlation values (evaluated basis functions for a single site, "
"normalized by cluster orbit size). The first argument is the linear unit "
"cell index [0, scel_vol). The second argument is the index of the site in "
"the neighbor list. For periodic cluster functions, the `neighbor_index` "
"counts over sites in the primitive cell that have site degrees of "
"freedom. If all sites in the prim have site degrees of freedom, then the "
"`neighbor_index` is equal to the `sublattice_index` of that site in the "
"prim. For local cluster functions, the `neighbor_index` counts over sites "
"in the neighborhood that have site degrees of freedom. The remaining "
"arguments follow the same conventions as `corr` accepting any of "
"`point_corr(linear_unitcell_index, neighbor_index)` or "
"`point_corr(linear_unitcell_index, neighbor_index, clex_name)` or "
"`point_corr(linear_unitcell_index, neighbor_index, indices)`, or "
"`point_corr(linear_unitcell_index, neighbor_index, clex_name, "
"indices)`. Coordinates of sites can be obtained from the `info -m "
"NeighborListInfo` method.";
Eigen::VectorXd PointCorr::evaluate(const Configuration &config) const {
return point_corr(m_linear_unitcell_index, m_neighbor_index, config,
m_clexulator);
}
/// \brief If not yet initialized, use the default clexulator from the PrimClex
bool PointCorr::init(const Configuration &_tmplt) const {
if (!m_clexulator.initialized()) {
const PrimClex &primclex = _tmplt.primclex();
ClexDescription desc = m_clex_name.empty()
? primclex.settings().default_clex()
: primclex.settings().clex(m_clex_name);
m_clexulator = primclex.clexulator(desc.bset);
}
VectorXdAttribute<Configuration>::init(_tmplt);
return true;
}
///
/// Expects one of:
/// - 'point_corr(linear_unitcell_index, neighbor_index)'
/// - 'point_corr(linear_unitcell_index, neighbor_index, clex_name)'
/// - 'point_corr(linear_unitcell_index, neighbor_index, index_expression)'
/// - 'point_corr(linear_unitcell_index, neighbor_index, clex_name,
/// index_expression)'
bool PointCorr::parse_args(const std::string &args) {
std::vector<std::string> splt_vec;
boost::split(splt_vec, args, boost::is_any_of(","), boost::token_compress_on);
if (splt_vec.size() < 2) {
return false;
}
if (splt_vec.size() == 2) {
m_linear_unitcell_index = std::stol(splt_vec[0]);
m_neighbor_index = std::stol(splt_vec[1]);
} else if (splt_vec.size() == 3) {
m_linear_unitcell_index = std::stol(splt_vec[0]);
m_neighbor_index = std::stol(splt_vec[1]);
if ((splt_vec[2].find_first_not_of("0123456789") == std::string::npos) ||
(splt_vec[2].find(':') != std::string::npos)) {
_parse_index_expression(splt_vec[2]);
} else {
m_clex_name = splt_vec[2];
}
} else if (splt_vec.size() == 4) {
m_linear_unitcell_index = std::stol(splt_vec[0]);
m_neighbor_index = std::stol(splt_vec[1]);
m_clex_name = splt_vec[2];
_parse_index_expression(splt_vec[3]);
} else {
std::stringstream ss;
ss << "Too many arguments for 'point_corr'. Received: " << args << "\n";
throw std::runtime_error(ss.str());
}
return true;
}
// --- AllCorrContribution implementations -----------
const std::string AllCorrContribution::Name = "all_corr_contribution";
const std::string AllCorrContribution::Desc =
"Correlation values (evaluated basis functions for a single unit cell, not "
"normalized), for every unitcell in the supercell. The output is a matrix, "
"with each row corresponding to a unitcell. The mean over rows is equal to "
"the `corr` output. The arguments follow the same conventions as `corr` "
"accepting any of:\n\n"
"- `all_corr_contribution`\n\n"
"- `all_corr_contribution(clex_name)`\n\n"
"- `all_corr_contribution(indices)`\n\n"
"- `all_corr_contribution(clex_name, indices)`. \n\n"
"Coordinates of unit cells can be obtained from the `unitcells` "
"information of the `info -m SupercellInfo` command.";
Eigen::MatrixXd AllCorrContribution::evaluate(
const Configuration &config) const {
return all_corr_contribution(config, m_clexulator);
}
/// \brief If not yet initialized, use the default clexulator from the PrimClex
bool AllCorrContribution::init(const Configuration &_tmplt) const {
if (!m_clexulator.initialized()) {
const PrimClex &primclex = _tmplt.primclex();
ClexDescription desc = m_clex_name.empty()
? primclex.settings().default_clex()
: primclex.settings().clex(m_clex_name);
m_clexulator = primclex.clexulator(desc.bset);
}
MatrixXdAttribute<Configuration>::init(_tmplt);
return true;
}
///
/// Expects one of:
/// - 'all_corr_contribution'
/// - 'all_corr_contribution(clex_name)'
/// - 'all_corr_contribution(index_expression)'
/// - 'all_corr_contribution(clex_name, index_expression)'
bool AllCorrContribution::parse_args(const std::string &args) {
std::vector<std::string> splt_vec;
boost::split(splt_vec, args, boost::is_any_of(","), boost::token_compress_on);
if (!splt_vec.size()) {
return true;
}
if (splt_vec.size() == 1) {
if ((splt_vec[0].find_first_not_of("0123456789") == std::string::npos) ||
(splt_vec[0].find(':') != std::string::npos)) {
_parse_index_expression(splt_vec[0]);
} else {
m_clex_name = splt_vec[0];
}
} else if (splt_vec.size() == 2) {
m_clex_name = splt_vec[0];
_parse_index_expression(splt_vec[1]);
} else {
std::stringstream ss;
ss << "Too many arguments for 'all_corr_contribution'. Received: " << args
<< "\n";
throw std::runtime_error(ss.str());
}
return true;
}
// --- SiteCentricCorrelations implementations -----------
const std::string SiteCentricCorrelations::Name = "site_centric_correlations";
const std::string SiteCentricCorrelations::Desc =
"Site-centric correlation values, the sum of all cluster functions that "
"include a particular site, normalized by cluster orbit size. The output "
"is a JSON object, with a \"value\" matrix of size (n_sites, "
"n_correlations) and an \"asymmetric_unit_indices\" array of size n_sites. "
"Each row in the \"value\" matrix contains the point correlations for a "
"site. The sum over rows normalized by supercell size (number of unit "
"cells) is equal to the global mean correlations (`corr`) times the "
"cluster size for functions associated with a given column (due to "
"multiple counting of cluster functions for each site involved in the "
"cluster). The i-th element of \"asymmetric_unit_indices\" gives the "
"asymmetric unit index for the site's sublattice (equal indices indicates "
"sites on symmetrically equivalent sublattices). Accepts either zero "
"arguments (`site_centric_correlations`), and uses the default cluster "
"expansion or one argument, (`site_centric_correlations(clex_name)`) and "
"uses the named cluster expansion. More detailed coordinates of sites for "
"any supercell can be obtained from the `info -m NeighborListInfo` method.";
jsonParser SiteCentricCorrelations::evaluate(
const Configuration &config) const {
Supercell const &supercell = config.supercell();
auto const &origin_unitcellcoords =
m_neighborhood_info->point_corr_unitcellcoord;
std::vector<Index> asymmetric_unit_indices;
for (xtal::UnitCellCoord unitcellcoord : origin_unitcellcoords) {
for (Index v = 0; v < supercell.volume(); ++v) {
asymmetric_unit_indices.push_back(
m_sublattice_to_asymmetric_unit[unitcellcoord.sublattice()]);
}
}
jsonParser json;
json["asymmetric_unit_indices"] = asymmetric_unit_indices;
json["value"] = all_point_corr(config, m_clexulator);
return json;
}
bool SiteCentricCorrelations::validate(const Configuration &config) const {
if (!m_neighborhood_info) {
CASM::err_log() << "Error in \"site_centric_correlations\": not properly "
"initialized (unknown error)."
<< std::endl;
return false;
}
return true;
}
/// \brief If not yet initialized, use the default clexulator from the PrimClex
bool SiteCentricCorrelations::init(const Configuration &_tmplt) const {
if (!m_clexulator.initialized()) {
const PrimClex &primclex = _tmplt.primclex();
auto const &prim = primclex.prim();
ClexDescription desc = m_clex_name.empty()
? primclex.settings().default_clex()
: primclex.settings().clex(m_clex_name);
ClexBasisSpecs const &basis_set_specs = primclex.basis_set_specs(desc.bset);
ClusterSpecs const &cluster_specs = *basis_set_specs.cluster_specs;
if (cluster_specs.periodicity_type() !=
CLUSTER_PERIODICITY_TYPE::PRIM_PERIODIC) {
throw std::runtime_error(
"Error: \"site_centric_correlations\" is only valid for periodic "
"cluster expansions.");
}
if (static_cast<PeriodicMaxLengthClusterSpecs const &>(cluster_specs)
.generating_group.size() != prim.factor_group().size()) {
throw std::runtime_error(
"Error: \"site_centric_correlations\" is only valid when the "
"generating group is the prim factor group.");
}
m_clexulator = primclex.clexulator(desc.bset);
m_neighborhood_info = &primclex.neighborhood_info(desc.bset);
adapter::Adapter<xtal::SymOpVector, SymGroup> adapter;
// set of [sets of basis indices of equivalent sites]
std::set<std::set<Index>> orbits =
xtal::make_asymmetric_unit(prim, adapter(prim.factor_group()));
m_sublattice_to_asymmetric_unit.resize(prim.basis().size());
Index asym_unit_index = 0;
for (std::set<Index> const &orbit : orbits) {
for (Index const &sublat : orbit) {
m_sublattice_to_asymmetric_unit[sublat] = asym_unit_index;
}
asym_unit_index++;
}
}
BaseValueFormatter<jsonParser, Configuration>::init(_tmplt);
return true;
}
/// Expects one of:
/// - 'site_centric_correlations'
/// - 'site_centric_correlations(clex_name)'
bool SiteCentricCorrelations::parse_args(const std::string &args) {
std::vector<std::string> splt_vec;
boost::split(splt_vec, args, boost::is_any_of(","), boost::token_compress_on);
if (!splt_vec.size()) {
return true;
} else if (splt_vec.size() == 1) {
m_clex_name = splt_vec[0];
} else {
std::stringstream ss;
ss << "Too many arguments for 'site_centric_correlations'. Received: "
<< args << "\n";
throw std::runtime_error(ss.str());
}
return true;
}
// --- AllPointCorr implementations -----------
const std::string AllPointCorr::Name = "all_point_corr";
/// \brief Returns point correlations from all sites, normalized by cluster
/// orbit size
///
/// \returns Matrix of size (n_sites, clexulator.corr_size()), where n_sites =
/// clexulator.n_point_corr() * config.supercell().volume().
///
/// Notes:
/// - The point correlations (each row in the result), described elsewhere in
/// CASM as "flower functions", are the values of all cluster functions that
/// include a particular site, normalized by cluster orbit size.
/// - The interpretation and application differs for periodic vs local cluster
/// expansions
/// - The value clexulator.n_point_corr() is the number of sites for which
/// point correlations can be evaluated (per unit cell), which is the sum of
/// cluster orbit size over all point cluster orbits.
const std::string AllPointCorr::Desc =
"Point correlation values, the sum of all cluster functions that include a "
"particular site, normalized by cluster orbit size, output as a JSON "
"object. The \"value\" is a matrix of size (n_sites, n_correlations). Each "
"row in the \"value\" matrix contains the point correlations for one site. "
"The interpretation and application differs for periodic vs local cluster "
"expansions. The sum over rows normalized by supercell size (number of "
"unit cells) is equal to the global mean correlations (`corr`) times the "
"cluster size for functions associated with a given column (due to "
"multiple counting of cluster functions for each site involved in the "
"cluster). Information about the sites is provided by the arrays (each of "
"size n_sites) \"asymmetric_unit_indices\" (equivalent indices indicates "
"symmetrically equivalent sites), \"linear_unitcell_index\" (indicates "
"which unit cell the functions were evaluated for), \"unitcellcoord\" (the "
"integral site coordinates (b, i, j, k) of the site, where b is the "
"sublattice index and (i,j,k) are integral coordinates of the unit cell "
"containing the site). Accepts either zero arguments (`all_point_corr`), "
"and uses the default cluster expansion or one argument, "
"(`all_point_corr(clex_name)`) and uses the named cluster expansion.";
jsonParser AllPointCorr::evaluate(const Configuration &config) const {
Supercell const &supercell = config.supercell();
jsonParser json;
json["asymmetric_unit_indices"] = make_all_point_corr_asymmetric_unit_indices(
*m_neighborhood_info, supercell.sym_info());
json["linear_unitcell_indices"] = make_all_point_corr_linear_unitcell_indices(
*m_neighborhood_info, supercell.sym_info());
json["unitcellcoord"] = make_all_point_corr_unitcellcoord(
*m_neighborhood_info, supercell.sym_info());
json["value"] = all_point_corr(config, m_clexulator);
return json;
}
bool AllPointCorr::validate(const Configuration &config) const {
if (!m_neighborhood_info) {
CASM::err_log() << "Error in AllPointCorr: not properly initialized."
<< std::endl;
return false;
}
return true;
}
/// \brief If not yet initialized, use the default clexulator from the PrimClex
bool AllPointCorr::init(const Configuration &_tmplt) const {
if (!m_clexulator.initialized()) {
const PrimClex &primclex = _tmplt.primclex();
ClexDescription desc = m_clex_name.empty()
? primclex.settings().default_clex()
: primclex.settings().clex(m_clex_name);
m_clexulator = primclex.clexulator(desc.bset);
m_neighborhood_info = &primclex.neighborhood_info(desc.bset);
}
BaseValueFormatter<jsonParser, Configuration>::init(_tmplt);
return true;
}
///
/// Expects one of:
/// - 'all_point_corr'
/// - 'all_point_corr(clex_name)'
bool AllPointCorr::parse_args(const std::string &args) {
std::vector<std::string> splt_vec;
boost::split(splt_vec, args, boost::is_any_of(","), boost::token_compress_on);
if (!splt_vec.size()) {
return true;
} else if (splt_vec.size() == 1) {
m_clex_name = splt_vec[0];
} else {
std::stringstream ss;
ss << "Too many arguments for 'all_point_corr'. Received: " << args
<< "\n";
throw std::runtime_error(ss.str());
}
return true;
}
// --- GradCorr implementations -----------
const std::string GradCorr::Name = "gradcorr";
const std::string GradCorr::Desc =
"Gradiant of correlation values (evaluated basis functions), with respect "
"to a specified "
"degree of freedom (DoF). For each configuration, output is a (D*N x C) "
"matrix, where 'D' "
"is DoF dimension, 'N' is either 1 (for global DoF) or number of sites in "
"the configuration "
"(for site DoF), and 'C' is number of basis functions. Gradient components "
"are ordered such "
"that components corresponding to particular site are listed in "
"consecutive rows. Requires "
"at least one argument, specifying the DoF with repect to which gradient "
"is taken [e.g., 'gradcorr(disp)']. "
"Basis functions are the basis set for the default cluster expansion, as "
"listed by 'casm settings -l', "
"unless otherwise specified. Accepts up to three additional arguments: "
"1) a cluster expansion name, e.g. 'gradcorr(disp,formation_energy)' "
"and/or "
"2) a pair of indices, or index ranges, e.g. 'gradcorr(disp,5,2)', "
"'gradcorr(disp,:,3:5)', 'gradcorr(disp,0:4,3)'";
/// \brief Returns the atom fraction
Eigen::MatrixXd GradCorr::evaluate(const Configuration &config) const {
return gradcorrelations(config, m_clexulator, m_key);
}
/// \brief If not yet initialized, use the default clexulator from the PrimClex
bool GradCorr::init(const Configuration &_tmplt) const {
if (!m_clexulator.initialized()) {
const PrimClex &primclex = _tmplt.primclex();
ClexDescription desc = m_clex_name.empty()
? primclex.settings().default_clex()
: primclex.settings().clex(m_clex_name);
m_clexulator = primclex.clexulator(desc.bset);
}
MatrixXdAttribute<Configuration>::init(_tmplt);
return true;
}
/// \brief Expects 'corr', 'corr(clex_name)', 'corr(index_expression)', or
/// 'corr(clex_name,index_expression)'
bool GradCorr::parse_args(const std::string &args) {
// std::cout << "parsing args: " << args << "\n";
std::vector<std::string> split_vec;
boost::split(split_vec, args, boost::is_any_of(","),
boost::token_compress_on);
// std::cout << "after split: " << split_vec << "\n";
if (!split_vec.size()) {
throw std::runtime_error(
"'gradcorr' query requires at least one argument, corresponding to the "
"independent variable wrt which gradient is to be computed.");
return false;
} else if (split_vec.size() > 4) {
std::stringstream ss;
ss << "Too many arguments for 'gradcorr'. Received: " << args << "\n";
throw std::runtime_error(ss.str());
}
boost::erase_all(split_vec[0], "'");
// std::cout << "Now split_vec[0] is " << split_vec[0] << "\n";
m_key = split_vec[0];
for (Index i = 1; i < split_vec.size(); ++i) {
if ((split_vec[i].find_first_not_of("0123456789") == std::string::npos) ||
(split_vec[i].find(':') != std::string::npos)) {
_parse_index_expression(split_vec[i] + "," + split_vec[i + 1]);
++i;
} else {
m_clex_name = split_vec[i];
}
}
return true;
}
// --- Clex implementations -----------
const std::string Clex::Name = "clex";
const std::string Clex::Desc =
"Predicted property value."
" Accepts arguments ($clex_name,$norm)."
" ($clex_name is a cluster expansion name as listed by 'casm settings -l', "
"default=the default clex)"
" ($norm is the normalization, either 'per_species', or 'per_unitcell' "
"<--default)";
Clex::Clex() : ScalarAttribute<Configuration>(Name, Desc) { parse_args(""); }
Clex::Clex(const Clexulator &clexulator, const ECIContainer &eci,
const Norm<Configuration> &norm)
: ScalarAttribute<Configuration>(Name, Desc),
m_clexulator(clexulator),
m_eci(eci),
m_norm(norm.clone()) {}
/// \brief Returns the atom fraction
double Clex::evaluate(const Configuration &config) const {
return m_eci * correlations(config, m_clexulator) / _norm(config);
}
/// \brief Clone using copy constructor
std::unique_ptr<Clex> Clex::clone() const {
return std::unique_ptr<Clex>(this->_clone());
}
/// \brief If not yet initialized, use the default cluster expansion from the
/// PrimClex
bool Clex::init(const Configuration &_tmplt) const {
if (!m_clexulator.initialized()) {
const PrimClex &primclex = _tmplt.primclex();
ClexDescription desc = m_clex_name.empty()
? primclex.settings().default_clex()
: primclex.settings().clex(m_clex_name);
m_clexulator = primclex.clexulator(desc.bset);
m_eci = primclex.eci(desc);
if (m_eci.index().back() >= m_clexulator.corr_size()) {
Log &err_log = CASM::err_log();
err_log.error<Log::standard>("bset and eci mismatch");
err_log << "basis set size: " << m_clexulator.corr_size() << std::endl;
err_log << "max eci index: " << m_eci.index().back() << std::endl;
throw std::runtime_error("Error: bset and eci mismatch");
}
}
return true;
}
/// \brief Expects 'clex', 'clex(formation_energy)', or
/// 'clex(formation_energy,per_species)'
bool Clex::parse_args(const std::string &args) {
std::vector<std::string> splt_vec;
boost::split(splt_vec, args, boost::is_any_of(","), boost::token_compress_on);
m_clex_name = "";
if (splt_vec.size()) {
m_clex_name = splt_vec[0];
}
m_norm = notstd::make_cloneable<Norm<Configuration>>();
if (splt_vec.size() == 2) {
if (splt_vec[1] == "per_unitcell") {
m_norm = notstd::make_cloneable<Norm<Configuration>>();
} else if (splt_vec[1] == "per_species") {
m_norm = notstd::make_cloneable<NormPerSpecies>();
} else {
std::stringstream ss;
ss << "Error parsing second argument for 'clex'. Received: " << args
<< "\n";
throw std::runtime_error(ss.str());
}
}
if (splt_vec.size() > 2) {
std::stringstream ss;
ss << "Too many arguments for 'clex'. Received: " << args << "\n";
throw std::runtime_error(ss.str());
}
return true;
}
/// \brief Returns the normalization
double Clex::_norm(const Configuration &config) const {
return (*m_norm)(config);
}
/// \brief Clone using copy constructor
Clex *Clex::_clone() const { return new Clex(*this); }
/*End ConfigIO*/
} // namespace ConfigIO
namespace ConfigIO {
GenericConfigFormatter<std::string> configname() {
return GenericConfigFormatter<std::string>(
"configname", "Configuration name, in the form 'SCEL#_#_#_#_#_#_#/#'",
[](const Configuration &config) -> std::string { return config.name(); });
}
GenericConfigFormatter<std::string> scelname() {
return GenericConfigFormatter<std::string>(
"scelname", "Supercell name, in the form 'SCEL#_#_#_#_#_#_#'",
[](const Configuration &config) -> std::string {
return config.supercell().name();
});
}
GenericConfigFormatter<std::string> calc_status() {
return GenericConfigFormatter<std::string>(
"calc_status",
"Status of calculation."
"A calculation that has been run successfully will be marked 'complete'."
"Mapped or imported configurations may have 'is_calculated = 1' without "
"'calc_status = complete'.",
[](const Configuration &config) -> std::string {
return CASM::calc_status<Configuration>(config);
},
[](const Configuration &config) -> bool {
return CASM::has_calc_status<Configuration>(config);
});
}
GenericConfigFormatter<std::string> failure_type() {
return GenericConfigFormatter<std::string>(
"failure_type", "Reason for calculation failure.",
[](const Configuration &config) -> std::string {
return CASM::failure_type<Configuration>(config);
},
[](const Configuration &config) -> bool {
return CASM::has_failure_type<Configuration>(config);
});
}
GenericConfigFormatter<Index> scel_size() {
return GenericConfigFormatter<Index>(
"scel_size",
"Supercell volume, given as the integer number of primitive cells",
[](const Configuration &config) -> Index {
return config.supercell().volume();
});
}
GenericConfigFormatter<Index> multiplicity() {
return GenericConfigFormatter<Index>(
"multiplicity",
"Symmetric multiplicity of the configuration, excluding translational "
"equivalents.",
[](const Configuration &config) -> Index {
return config.multiplicity();
});
}
GenericConfigFormatter<std::string> point_group_name() {
return GenericConfigFormatter<std::string>(
"point_group_name", "Name of the configuration's point group.",
[](const Configuration &config) -> std::string {
return config.point_group_name();
});
}
// deprecated for 'energy'
GenericConfigFormatter<double> relaxed_energy() {
return GenericConfigFormatter<double>(
"relaxed_energy",
"DFT energy, normalized per primitive cell (deprecated for `energy`)",
CASM::energy, has_energy);
}
GenericConfigFormatter<double> energy() {
return GenericConfigFormatter<double>(
"energy", "DFT energy, normalized per primitive cell", CASM::energy,
has_energy);
}
// deprecated for 'energy_per_species'
GenericConfigFormatter<double> relaxed_energy_per_species() {
return GenericConfigFormatter<double>(
"relaxed_energy_per_atom",
"DFT energy, normalized per atom (deprecated for `energy_per_atom`)",
CASM::energy_per_species, has_energy);
}
GenericConfigFormatter<double> energy_per_species() {
return GenericConfigFormatter<double>("energy_per_atom",
"DFT energy, normalized per atom",
CASM::energy_per_species, has_energy);
}
GenericConfigFormatter<double> reference_energy() {
return GenericConfigFormatter<double>(
"reference_energy",
"reference energy, normalized per primitive cell, as determined by "
"current reference states",
CASM::reference_energy, has_reference_energy);
}
GenericConfigFormatter<double> reference_energy_per_species() {
return GenericConfigFormatter<double>(
"reference_energy_per_atom",
"reference energy, normalized per atom, as determined by current "
"reference states",
CASM::reference_energy_per_species, has_reference_energy);
}
GenericConfigFormatter<double> formation_energy() {
return GenericConfigFormatter<double>(
"formation_energy",
"DFT formation energy, normalized per primitive cell and measured "
"relative to current reference states",
CASM::formation_energy, has_formation_energy);
}
GenericConfigFormatter<double> formation_energy_per_species() {
return GenericConfigFormatter<double>(
"formation_energy_per_atom",
"DFT formation energy, normalized per atom and measured relative to "
"current reference states",
CASM::formation_energy_per_species, has_formation_energy);
}
/*Generic1DDatumFormatter<std::vector<double>, Configuration
>relaxation_strain() { return Generic1DDatumFormatter<std::vector<double>,
Configuration >("relaxation_strain", "Green-Lagrange strain of dft-relaxed
configuration, relative to the ideal crystal. Ordered as [E(0,0), E(1,1),
E(2,2), E(1,2), E(0,2), E(0,1)]. Accepts index as argument on interval
[0,5]", CASM::relaxation_strain, has_relaxation_strain,
[](const std::vector<double> &cont)->Index{