Statistiques
| Révision :

root / ase / calculators / jacapo / changed.py @ 8

Historique | Voir | Annoter | Télécharger (4,55 ko)

1
import numpy as np
2

    
3
import logging
4
log = logging.getLogger('Jacapo')
5

    
6
'''
7
provides functions to determine if an input parameter has changed.
8
'''
9

    
10
#######################################################################
11
#### changed functions
12

    
13
def kpts_changed(calc, x):
14
    '''
15
    check if kpt grid has changed.
16

17
    we have to take care to generate teh right k-points from x if
18
    needed. if a user provides (4,4,4) we need to generate the MP
19
    grid, etc...
20

21
    Since i changed the MP code in set_kpts, there is some
22
    incompatibility with old jacapo calculations and their MP
23
    grids.
24
    '''
25
    #chadi-cohen
26
    if isinstance(x, str):
27
        exec('from ase.dft.kpoints import %s' % kpts)
28
        listofkpts = eval(kpts)
29
    #monkhorst-pack grid
30
    elif np.array(x).shape == (3,):
31
        from ase.dft.kpoints import monkhorst_pack
32
        N1, N2, N3 = x
33
        listofkpts = monkhorst_pack((N1, N2, N3))
34
    #user-defined list is provided
35
    elif len(np.array(x).shape) == 2:
36
        listofkpts = np.array(x)
37
    else:
38
        raise Exception, 'apparent invalid setting for kpts'
39

    
40
    grid = calc.get_kpts()
41

    
42
    if grid.shape != listofkpts.shape:
43
        return True
44

    
45
    if (abs(listofkpts - grid) < 1e-6).all():
46
        return False
47
    else:
48
        return True
49

    
50
def electronic_minimization_changed(calc, x):
51
    myx = calc.get_electronic_minimization()
52

    
53
    for key in myx:
54
        if myx[key] != x[key]:
55
            print key, myx[key], ' changed to ', x[key]
56
            return True
57
    return False
58

    
59
def spinpol_changed(calc, x):
60
    if x != calc.get_spinpol():
61
        return True
62
    else:
63
        return False
64

    
65
def symmetry_changed(calc, x):
66
    if x != calc.get_symmetry():
67
        return True
68
    else:
69
        return False
70

    
71
def xc_changed(calc, x):
72
    if x != calc.get_xc():
73
        return True
74
    return False
75

    
76
def calculate_stress_changed(calc, x):
77
    if x != calc.get_calculate_stress():
78
        return True
79
    return False
80

    
81
def ados_changed(calc, x):
82
    ados = calc.get_ados()
83

    
84
    #ados may not be defined, and then None is returned
85
    if ados is None and x is None:
86
        return False
87
    elif ados is None and x is not None:
88
        return True
89
    elif ados is not None and x is None:
90
        return True
91

    
92
    #getting here means ados and x are not none so we compare them
93
    for key in x:
94
        try:
95
            if x[key] != ados[key]:
96
                return True
97
        except ValueError:
98
            if (x[key] != ados[key]).all():
99
                return True
100
    return False
101

    
102
def convergence_changed(calc, x):
103
    conv = calc.get_convergence()
104
    for key in x:
105
        if x[key] != conv[key]:
106
            return True
107
    return False
108

    
109
def charge_mixing_changed(calc, x):
110
    cm = calc.get_charge_mixing()
111
    if x is None and cm is None:
112
        return False
113
    else:
114
        return True
115
        
116
    for key in x:
117
        if x[key] != cm[key]:
118
            return True
119
    return False
120

    
121
def decoupling_changed(calc, x):
122
    pars = calc.get_decoupling()
123
    for key in x:
124
        if x[key] != pars[key]:
125
            return True
126
    return False
127

    
128
def dipole_changed(calc, x):
129
    pars = calc.get_dipole()
130
    if pars is False and x is False:
131
        return False
132
    elif pars is not False:
133
        for key in x:
134
            if x[key] != pars[key]:
135
                return True
136
        return False
137

    
138
def extpot_changed(calc, x):
139
    extpot = calc.get_extpot()
140
    if (x == extpot).all():
141
        return False
142
    return True
143

    
144
def fftgrid_changed(calc, x):
145
    validkeys = ['soft', 'hard']
146

    
147
    myx = calc.get_fftgrid()
148
    if (myx['soft'] == x['soft'] and myx['hard'] == x['hard']):
149
        return False
150
    else:
151
        return True
152

    
153

    
154
def nbands_changed(calc, x):
155
    if calc.get_nbands() == x:
156
        return False
157
    else:
158
        return True
159

    
160
def occupationstatistics_changed(calc, x):
161
    if calc.get_occupationstatistics() == x:
162
        return False
163
    else:
164
        return True
165

    
166
def pw_changed(calc, x):
167
    if calc.get_pw() == x:
168
        return False
169
    else:
170
        return True
171

    
172
def dw_changed(calc, x):
173
    if calc.get_dw() == x:
174
        return False
175
    else:
176
        return True
177

    
178
def ft_changed(calc, x):
179
    if calc.get_ft() == x:
180
        return False
181
    else:
182
        return True
183
    
184
def mdos_changed(calc,x):
185

    
186
    myx = calc.get_mdos()
187

    
188
    log.debug('myx = %s' % str(myx))
189
    log.debug('x = %s' % str(x))
190

    
191
    if x is None and myx is None:
192
        return False
193
    elif ((x is None and myx is not None)
194
        or (x is not None and myx is None)):
195
        return True
196
    else:
197
        for key in x:
198
            if x[key] != myx[key]:
199
                return True
200
    return False