25
25
26
26
using namespace std ;
27
27
using diffpy::srreal::BVSCalculator;
28
+ using diffpy::srreal::BVParametersTablePtr;
28
29
using diffpy::srreal::StructureAdapterPtr;
30
+ using diffpy::srreal::PeriodicStructureAdapter;
31
+ using diffpy::srreal::PeriodicStructureAdapterPtr;
29
32
30
33
// ////////////////////////////////////////////////////////////////////////////
31
34
// class TestBVSCalculator
@@ -76,6 +79,39 @@ class TestBVSCalculator : public CxxTest::TestSuite
76
79
}
77
80
78
81
82
+ void test_customAtomValences ()
83
+ {
84
+ using diffpy::srreal::Atom;
85
+ const double eps = 1e-4 ;
86
+ mbvc->eval (mnacl);
87
+ TS_ASSERT_DELTA (0.01352 , mbvc->bvrmsdiff (), eps);
88
+ BVParametersTablePtr bvtb = mbvc->getBVParamTable ();
89
+ bvtb->setAtomValence (" Cl1-" , 0 );
90
+ mbvc->eval (mnacl);
91
+ TS_ASSERT_EQUALS (0.0 , mbvc->value ()[0 ]);
92
+ TS_ASSERT_EQUALS (0.0 , mbvc->value ()[4 ]);
93
+ // create structure with bare atom symbols "Na", "Cl".
94
+ PeriodicStructureAdapterPtr naclbare =
95
+ boost::dynamic_pointer_cast<
96
+ PeriodicStructureAdapter>(mnacl->clone ());
97
+ for (int i = 0 ; i < naclbare->countSites (); ++i)
98
+ {
99
+ Atom& a = naclbare->at (i);
100
+ a.atomtype = a.atomtype .substr (0 , 2 );
101
+ }
102
+ TS_ASSERT_EQUALS (string (" Na" ), naclbare->siteAtomType (0 ));
103
+ // verify valence sums are zero for a standard setup.
104
+ mbvc->eval (naclbare);
105
+ TS_ASSERT_EQUALS (0.0 , mbvc->value ()[0 ]);
106
+ TS_ASSERT_EQUALS (0.0 , mbvc->value ()[4 ]);
107
+ // verify valence sums with custom atom valences.
108
+ bvtb->setAtomValence (" Na" , +1 );
109
+ bvtb->setAtomValence (" Cl" , -1 );
110
+ mbvc->eval (naclbare);
111
+ TS_ASSERT_DELTA (0.01352 , mbvc->bvrmsdiff (), eps);
112
+ }
113
+
114
+
79
115
void test_setValencePrecision ()
80
116
{
81
117
TS_ASSERT_THROWS (mbvc->setValencePrecision (0 ), invalid_argument);
@@ -97,6 +133,10 @@ class TestBVSCalculator : public CxxTest::TestSuite
97
133
mbvc->setValencePrecision (1e-7 );
98
134
mbvc->setDoubleAttr (" rmax" , 5.0 );
99
135
TS_ASSERT_EQUALS (5.0 , mbvc->getDoubleAttr (" rmaxused" ));
136
+ // check if value updates with changes in the table.
137
+ BVParametersTablePtr bvtb = mbvc->getBVParamTable ();
138
+ bvtb->setCustom (" Na" , 1 , " Cl" , -1 , 0.0 , 0 );
139
+ TS_ASSERT_EQUALS (0.0 , mbvc->getDoubleAttr (" rmaxused" ));
100
140
}
101
141
102
142
0 commit comments