def test___init__(self): """check BVSCalculator.__init__() """ self.assertEqual(1e-5, self.bvc.valenceprecision) bvc1 = BVSCalculator(valenceprecision=1e-4) self.assertEqual(1e-4, bvc1.valenceprecision) return
def setUp(self): self.bvc = BVSCalculator() if not hasattr(self, 'rutile'): type(self).rutile = loadDiffPyStructure('rutile.cif') # rutile.cif does not have charge data, we need to add them here iondict = {'Ti': 'Ti4+', 'O': 'O2-'} for a in self.rutile: a.element = iondict[a.element] return
def test_pickling(self): '''check pickling and unpickling of BVSCalculator. ''' bvsc = BVSCalculator() bvsc.rmin = 0.1 bvsc.rmax = 12.3 bvsc.valenceprecision = 0.3e-4 spkl = pickle.dumps(bvsc) bvsc1 = pickle.loads(spkl) self.assertFalse(bvsc is bvsc1) for a in bvsc._namesOfDoubleAttributes(): self.assertEqual(getattr(bvsc, a), getattr(bvsc1, a)) self.assertRaises(RuntimeError, pickle_with_attr, bvsc, foo='bar') return
def test_pickling(self): '''check pickling and unpickling of BVSCalculator. ''' bvsc = BVSCalculator() bvsc.rmin = 0.1 bvsc.rmax = 12.3 bvsc.valenceprecision = 0.3e-4 bvsc.foobar = 'asdf' spkl = cPickle.dumps(bvsc) bvsc1 = cPickle.loads(spkl) self.failIf(bvsc is bvsc1) for a in bvsc._namesOfDoubleAttributes(): self.assertEqual(getattr(bvsc, a), getattr(bvsc1, a)) self.assertEqual('asdf', bvsc1.foobar) return
def __init__(self, parset, sig=1, scaled=False): """Initialize the Restraint. parset -- SrRealParSet that creates this BVSRestraint. sig -- The uncertainty on the BVS (default 1). scaled -- A flag indicating if the restraint is scaled (multiplied) by the unrestrained point-average chi^2 (chi^2/numpoints) (bool, default False). """ from diffpy.srreal.bvscalculator import BVSCalculator self._calc = BVSCalculator() self._parset = parset self.sig = float(sig) self.scaled = bool(scaled) return
def test_bvs_to_xarray(db): stru = db["Ni_stru"] calc = BVSCalculator() calc(stru) arr = bvs_to_xarray(calc) print(arr)
#!/usr/bin/env python # -*- coding: utf-8 -*- '''Calculation of bond valence sums using diffpy.srreal module included in DiffPy-CMI. ''' from __future__ import print_function from diffpy.Structure import loadStructure from diffpy.srreal.bvscalculator import BVSCalculator # load crystal structure data from a CIF file nacl = loadStructure('NaCl.cif') # create bond valence sum calculator object bvsc = BVSCalculator() # calculate BVS and print the expected and actual valences vsim = bvsc(nacl) print('Calculate bond valence sums for NaCl "bvsc(nacl)"') print('expected "bvsc.valences":\n ', bvsc.valences) print('calculated "bvsc.value":\n ' , vsim) print('difference "bvsc.bvdiff":\n ', bvsc.bvdiff) print('root mean square difference "bvsc.bvrmsdiff":', bvsc.bvrmsdiff) print() # create new BVS calculator with a custom bond valence parameters bvsc2 = BVSCalculator() # Use alternate value for the Na+ Cl- bond valence parameters from # http://www.iucr.org/__data/assets/file/0018/59004/bvparm2011.cif