-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathdistanceprinter.py
executable file
·81 lines (68 loc) · 2.46 KB
/
distanceprinter.py
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
#!/usr/bin/env python
"""Demonstration of using PairQuantity class for a printout
of pair distances in periodic and non-periodic structures.
"""
from diffpy.srreal.pairquantity import PairQuantity
from diffpy.structure import Structure
class DistancePrinter(PairQuantity):
'''This PairQuantity class simply prints the visited pair distances
and the indices of the contributing atoms.
'''
def _resetValue(self):
self.count = 0
def _addPairContribution(self, bnds, sumscale):
self.count += bnds.multiplicity() * sumscale / 2.0
print("%i %g %i %i" % (
self.count, bnds.distance(), bnds.site0(), bnds.site1()))
return
# class DistancePrinter
# define nickel structure data
nickel_discus_data = '''
title Ni
spcgr P1
cell 3.523870, 3.523870, 3.523870, 90.000000, 90.000000, 90.000000
ncell 1, 1, 1, 4
atoms
NI 0.00000000 0.00000000 0.00000000 0.1000
NI 0.00000000 0.50000000 0.50000000 0.1000
NI 0.50000000 0.00000000 0.50000000 0.1000
NI 0.50000000 0.50000000 0.00000000 0.1000
'''
nickel = Structure()
nickel.readStr(nickel_discus_data, format='discus')
bucky = Structure(filename='datafiles/C60bucky.stru', format='discus')
distprint = DistancePrinter()
distprint._setDoubleAttr('rmax', 10)
def get_pyobjcryst_sphalerite():
from pyobjcryst.crystal import create_crystal_from_cif
crst = create_crystal_from_cif('datafiles/sphalerite.cif')
return crst
def main():
s = input('Enter rmin: ')
if s.strip(): distprint.rmin = float(s)
print("rmin = %g" % distprint.rmin)
s = input('Enter rmax: ')
if s.strip(): distprint.rmax = float(s)
print("rmax = %g" % distprint.rmax)
print()
linesep = 78 * '-'
# C60bucky
print(linesep)
input('Press enter for distances in C60 molecule.')
distprint.eval(bucky)
# nickel
print(linesep)
input('Press enter for distances in a nickel crystal.')
distprint.eval(nickel)
# objcryst sphalerite
print(linesep)
input('Press enter for distances in objcryst loaded sphalerite.cif.')
crst = get_pyobjcryst_sphalerite()
distprint.eval(crst)
print(linesep)
input('Press enter for distances in diffpy.structure sphalerite.cif.')
crst = Structure(filename='datafiles/sphalerite.cif')
distprint.eval(crst)
return
if __name__ == '__main__':
main()