2525
2626using namespace std ;
2727using diffpy::srreal::BVSCalculator;
28+ using diffpy::srreal::BVParametersTablePtr;
2829using diffpy::srreal::StructureAdapterPtr;
30+ using diffpy::srreal::PeriodicStructureAdapter;
31+ using diffpy::srreal::PeriodicStructureAdapterPtr;
2932
3033// ////////////////////////////////////////////////////////////////////////////
3134// class TestBVSCalculator
@@ -76,6 +79,39 @@ class TestBVSCalculator : public CxxTest::TestSuite
7679 }
7780
7881
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+
79115 void test_setValencePrecision ()
80116 {
81117 TS_ASSERT_THROWS (mbvc->setValencePrecision (0 ), invalid_argument);
@@ -97,6 +133,10 @@ class TestBVSCalculator : public CxxTest::TestSuite
97133 mbvc->setValencePrecision (1e-7 );
98134 mbvc->setDoubleAttr (" rmax" , 5.0 );
99135 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" ));
100140 }
101141
102142
0 commit comments