-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalcPlugin_ASE.py
116 lines (94 loc) · 3.27 KB
/
CalcPlugin_ASE.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
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
import numpy as np
from ase.utils.xrdebye import XrDebye, wavelengths
from PluginBase import PluginBase
class CalcPlugin_ASE(PluginBase):
"""
"""
AVAILABLE_PROPERTIES = ["XRD",
"SANS"]
def __init__(self, parent=None):
"""
no state here
"""
self._name = "ASE"
pass
# base method overrides
def name(self):
"""
plugin name getter
"""
return self._name
def canCalculate(self, prop=None):
"""
Check if this plugin can calculate requested property
"""
if prop is None:
return True
if prop.upper() in self.AVAILABLE_PROPERTIES:
return True
else:
return False
def startBackend(self, **kwargs):
"""
Start/connect to the 3rd party backend
"""
# Nothing to start for ASE
pass
def getProperty(self, prop="", **kwargs):
"""
"""
if not prop:
return None
prop = prop.upper()
if not self.canCalculate(prop):
txt = "The ASE plugin does not support calculations of " + prop + "."
raise NotImplementedError(txt)
# get the property from ASE
method_name = "get"+prop
method = getattr(self, method_name)
try:
result = method(**kwargs)
except Exception as ex:
# re-raise with meaningful message
msg = "ASE Calculation of " +prop+ " failed with: \n"
msg += str(ex)
raise RuntimeError()
return result
# Property calculate wrappers
def getXRD(self, **kwargs):
"""
calculate XRD
"""
wavelength = None
if 'wavelength' in kwargs:
wavelength = kwargs['wavelength']
if 'structure' not in kwargs:
raise NameError("Structure not found!")
structure = kwargs['structure']
if wavelength is None or structure is None:
raise RuntimeError("ASE Calculator cannot evaluate XRD - not enough parameters!")
ase_atoms = structure.aseStructure()
xrd_object = XrDebye(atoms=ase_atoms, wavelength=wavelength)
# Equally spaced list of 2theta values
angles_list = np.arange(15, 30, 0.1)
# Get the xray diffraction pattern for these points
intensity_list = xrd_object.calc_pattern(x=np.arange(15, 30, 0.1), mode='XRD')
# Return the list of tuples
return zip(angles_list, intensity_list)
# xrd_object.plot_pattern(filename=None)
def getSANS(self, **kwargs):
"""
calculate XRD
"""
wavelength = None
if 'wavelength' in kwargs:
wavelength = kwargs['wavelength']
if 'structure' not in kwargs:
raise NameError("Structure not found!")
structure = kwargs['structure']
if wavelength is None or structure is None:
raise RuntimeError("ASE Calculator cannot evaluate SANS - not enough parameters!")
ase_atoms = structure.aseStructure()
xrd_object = XrDebye(atoms=ase_atoms, wavelength=wavelength)
xrd_object.calc_pattern(x=np.logspace(-2, -0.3, 50), mode='SAXS')
xrd_object.plot_pattern(filename=None)