1
2import versions
3import testing
4from testing import divert_nexus_log,restore_nexus_log
5from testing import value_eq,object_eq
6
7associated_files = dict()
8
9def get_files():
10    return testing.collect_unit_test_file_paths('qmcpack_input',associated_files)
11#end def get_files
12
13
14def format_value(v):
15    import numpy as np
16    s = ''
17    if isinstance(v,np.ndarray):
18        pad = 12*' '
19        s = 'np.array([\n'
20        if len(v.shape)==1:
21            s += pad
22            for vv in v:
23                s += format_value(vv)+','
24            #end for
25            s = s[:-1]
26        else:
27            for vv in v:
28                s += pad + format_value(list(vv))+',\n'
29            #end for
30            s = s[:-2]
31        #end if
32        s += '])'
33    elif isinstance(v,(str,np.string_)):
34        s = "'"+v+"'"
35    else:
36        s = str(v)
37    #end if
38    return s
39#end def format_value
40
41
42def make_serial_reference(qi):
43    s = qi.serial()
44    ref = '    ref = {\n'
45    for k in sorted(s.keys()):
46        v = s[k]
47        ref +="        '{}' : {},\n".format(k,format_value(v))
48    #end for
49    ref += '        }\n'
50    return ref
51#end def make_serial_reference
52
53
54serial_references = dict()
55
56
57def generate_serial_references():
58    import numpy as np
59    from qmcpack_input import onerdm
60
61    # reference for read/write
62    ref = {
63        '_metadata/lattice/units' : 'bohr',
64        '_metadata/position/condition' : '0',
65        '_metadata/position/datatype' : 'posArray',
66        'simulation/calculations/0/blocks' : 70,
67        'simulation/calculations/0/checkpoint' : -1,
68        'simulation/calculations/0/method' : 'vmc',
69        'simulation/calculations/0/move' : 'pbyp',
70        'simulation/calculations/0/samplesperthread' : 2,
71        'simulation/calculations/0/steps' : 5,
72        'simulation/calculations/0/substeps' : 2,
73        'simulation/calculations/0/timestep' : 0.3,
74        'simulation/calculations/0/walkers' : 1,
75        'simulation/calculations/0/warmupsteps' : 20,
76        'simulation/calculations/1/blocks' : 80,
77        'simulation/calculations/1/checkpoint' : -1,
78        'simulation/calculations/1/method' : 'dmc',
79        'simulation/calculations/1/move' : 'pbyp',
80        'simulation/calculations/1/nonlocalmoves' : 'yes',
81        'simulation/calculations/1/steps' : 5,
82        'simulation/calculations/1/timestep' : 0.02,
83        'simulation/calculations/1/warmupsteps' : 2,
84        'simulation/calculations/2/blocks' : 600,
85        'simulation/calculations/2/checkpoint' : -1,
86        'simulation/calculations/2/method' : 'dmc',
87        'simulation/calculations/2/move' : 'pbyp',
88        'simulation/calculations/2/nonlocalmoves' : 'yes',
89        'simulation/calculations/2/steps' : 5,
90        'simulation/calculations/2/timestep' : 0.005,
91        'simulation/calculations/2/warmupsteps' : 10,
92        'simulation/project/application/class_' : 'serial',
93        'simulation/project/application/name' : 'qmcapp',
94        'simulation/project/application/role' : 'molecu',
95        'simulation/project/application/version' : 1.0,
96        'simulation/project/id' : 'qmc',
97        'simulation/project/series' : 0,
98        'simulation/qmcsystem/hamiltonians/h0/estimators/KEcorr/name' : 'KEcorr',
99        'simulation/qmcsystem/hamiltonians/h0/estimators/KEcorr/psi' : 'psi0',
100        'simulation/qmcsystem/hamiltonians/h0/estimators/KEcorr/source' : 'e',
101        'simulation/qmcsystem/hamiltonians/h0/estimators/KEcorr/type' : 'chiesa',
102        'simulation/qmcsystem/hamiltonians/h0/estimators/SpinDensity/grid' : np.array([
103            72,44,44]),
104        'simulation/qmcsystem/hamiltonians/h0/estimators/SpinDensity/name' : 'SpinDensity',
105        'simulation/qmcsystem/hamiltonians/h0/estimators/SpinDensity/type' : 'spindensity',
106        'simulation/qmcsystem/hamiltonians/h0/name' : 'h0',
107        'simulation/qmcsystem/hamiltonians/h0/pairpots/ElecElec/name' : 'ElecElec',
108        'simulation/qmcsystem/hamiltonians/h0/pairpots/ElecElec/source' : 'e',
109        'simulation/qmcsystem/hamiltonians/h0/pairpots/ElecElec/target' : 'e',
110        'simulation/qmcsystem/hamiltonians/h0/pairpots/ElecElec/type' : 'coulomb',
111        'simulation/qmcsystem/hamiltonians/h0/pairpots/IonIon/name' : 'IonIon',
112        'simulation/qmcsystem/hamiltonians/h0/pairpots/IonIon/source' : 'ion0',
113        'simulation/qmcsystem/hamiltonians/h0/pairpots/IonIon/target' : 'ion0',
114        'simulation/qmcsystem/hamiltonians/h0/pairpots/IonIon/type' : 'coulomb',
115        'simulation/qmcsystem/hamiltonians/h0/pairpots/MPC/ecut' : 60.0,
116        'simulation/qmcsystem/hamiltonians/h0/pairpots/MPC/name' : 'MPC',
117        'simulation/qmcsystem/hamiltonians/h0/pairpots/MPC/physical' : False,
118        'simulation/qmcsystem/hamiltonians/h0/pairpots/MPC/source' : 'e',
119        'simulation/qmcsystem/hamiltonians/h0/pairpots/MPC/target' : 'e',
120        'simulation/qmcsystem/hamiltonians/h0/pairpots/MPC/type' : 'MPC',
121        'simulation/qmcsystem/hamiltonians/h0/pairpots/PseudoPot/format' : 'xml',
122        'simulation/qmcsystem/hamiltonians/h0/pairpots/PseudoPot/name' : 'PseudoPot',
123        'simulation/qmcsystem/hamiltonians/h0/pairpots/PseudoPot/pseudos/O/elementtype' : 'O',
124        'simulation/qmcsystem/hamiltonians/h0/pairpots/PseudoPot/pseudos/O/href' : 'O.opt.xml',
125        'simulation/qmcsystem/hamiltonians/h0/pairpots/PseudoPot/pseudos/V/elementtype' : 'V',
126        'simulation/qmcsystem/hamiltonians/h0/pairpots/PseudoPot/pseudos/V/href' : 'V.opt.xml',
127        'simulation/qmcsystem/hamiltonians/h0/pairpots/PseudoPot/source' : 'ion0',
128        'simulation/qmcsystem/hamiltonians/h0/pairpots/PseudoPot/type' : 'pseudo',
129        'simulation/qmcsystem/hamiltonians/h0/pairpots/PseudoPot/wavefunction' : 'psi0',
130        'simulation/qmcsystem/hamiltonians/h0/target' : 'e',
131        'simulation/qmcsystem/hamiltonians/h0/type' : 'generic',
132        'simulation/qmcsystem/particlesets/e/groups/d/charge' : -1,
133        'simulation/qmcsystem/particlesets/e/groups/d/mass' : 1.0,
134        'simulation/qmcsystem/particlesets/e/groups/d/name' : 'd',
135        'simulation/qmcsystem/particlesets/e/groups/d/size' : 200,
136        'simulation/qmcsystem/particlesets/e/groups/u/charge' : -1,
137        'simulation/qmcsystem/particlesets/e/groups/u/mass' : 1.0,
138        'simulation/qmcsystem/particlesets/e/groups/u/name' : 'u',
139        'simulation/qmcsystem/particlesets/e/groups/u/size' : 200,
140        'simulation/qmcsystem/particlesets/e/name' : 'e',
141        'simulation/qmcsystem/particlesets/e/random' : True,
142        'simulation/qmcsystem/particlesets/ion0/groups/O/atomicnumber' : 8,
143        'simulation/qmcsystem/particlesets/ion0/groups/O/charge' : 6,
144        'simulation/qmcsystem/particlesets/ion0/groups/O/mass' : 29164.3928678,
145        'simulation/qmcsystem/particlesets/ion0/groups/O/name' : 'O',
146        'simulation/qmcsystem/particlesets/ion0/groups/O/position' : np.array([
147            [0.00978311, 1.81708472, 1.78656736],
148            [10.85992161, 15.33331378, -1.78656738],
149            [2.75326234, 11.04571415, -2.495713],
150            [8.1164424, 6.10468435, 2.495713],
151            [2.71381355, 6.02493499, 2.55909075],
152            [8.15589117, 11.12546351, -2.55909075],
153            [5.45729278, 15.41306313, -1.72318961],
154            [5.41241194, 1.73733537, 1.72318961],
155            [10.87948783, 1.81708472, 1.78656736],
156            [21.72962633, 15.33331378, -1.78656738],
157            [13.62296706, 11.04571415, -2.495713],
158            [18.98614712, 6.10468435, 2.495713],
159            [13.58351827, 6.02493499, 2.55909075],
160            [19.02559589, 11.12546351, -2.55909075],
161            [16.3269975, 15.41306313, -1.72318961],
162            [16.28211666, 1.73733537, 1.72318961],
163            [0.00978311, 10.39228397, 1.78656736],
164            [10.85992161, 6.75811453, -1.78656738],
165            [-2.7336961, 11.04571415, 6.06884775],
166            [13.60340084, 6.10468435, -6.06884775],
167            [8.20077199, 6.02493499, -6.00547],
168            [2.66893273, 11.12546351, 6.00547],
169            [5.45729278, 6.83786388, -1.72318961],
170            [5.41241194, 10.31253462, 1.72318961],
171            [10.87948783, 10.39228397, 1.78656736],
172            [21.72962633, 6.75811453, -1.78656738],
173            [8.13600862, 11.04571415, 6.06884775],
174            [24.47310556, 6.10468435, -6.06884775],
175            [19.07047671, 6.02493499, -6.00547],
176            [13.53863745, 11.12546351, 6.00547],
177            [16.3269975, 6.83786388, -1.72318961],
178            [16.28211666, 10.31253462, 1.72318961]]),
179        'simulation/qmcsystem/particlesets/ion0/groups/O/size' : 32,
180        'simulation/qmcsystem/particlesets/ion0/groups/O/valence' : 6,
181        'simulation/qmcsystem/particlesets/ion0/groups/V/atomicnumber' : 23,
182        'simulation/qmcsystem/particlesets/ion0/groups/V/charge' : 13,
183        'simulation/qmcsystem/particlesets/ion0/groups/V/mass' : 92861.5851912,
184        'simulation/qmcsystem/particlesets/ion0/groups/V/name' : 'V',
185        'simulation/qmcsystem/particlesets/ion0/groups/V/position' : np.array([
186            [2.45778327, 8.39460555, 0.22661828],
187            [8.41192147, 8.75579295, -0.22661828],
188            [5.2012625, 13.04339257, -4.0556621],
189            [5.66844224, 4.10700593, 4.0556621],
190            [13.32748799, 8.39460555, 0.22661828],
191            [19.28162619, 8.75579295, -0.22661828],
192            [16.07096722, 13.04339257, -4.0556621],
193            [16.53814696, 4.10700593, 4.0556621],
194            [7.94474171, 8.39460555, -8.33794247],
195            [2.92496303, 8.75579295, 8.33794247],
196            [5.2012625, 4.46819332, -4.0556621],
197            [5.66844224, 12.68220518, 4.0556621],
198            [18.81444643, 8.39460555, -8.33794247],
199            [13.79466775, 8.75579295, 8.33794247],
200            [16.07096722, 4.46819332, -4.0556621],
201            [16.53814696, 12.68220518, 4.0556621]]),
202        'simulation/qmcsystem/particlesets/ion0/groups/V/size' : 16,
203        'simulation/qmcsystem/particlesets/ion0/groups/V/valence' : 13,
204        'simulation/qmcsystem/particlesets/ion0/name' : 'ion0',
205        'simulation/qmcsystem/simulationcell/bconds' : np.array([
206            'p','p','p']),
207        'simulation/qmcsystem/simulationcell/lattice' : np.array([
208            [21.73940944, 0.0, 0.0],
209            [5.48695844, 8.57519925, -8.56456075],
210            [-5.48695844, 8.57519925, 8.56456075]]),
211        'simulation/qmcsystem/simulationcell/lr_dim_cutoff' : 15,
212        'simulation/qmcsystem/wavefunctions/psi0/determinantset/slaterdeterminant/determinants/downdet/group' : 'd',
213        'simulation/qmcsystem/wavefunctions/psi0/determinantset/slaterdeterminant/determinants/downdet/id' : 'downdet',
214        'simulation/qmcsystem/wavefunctions/psi0/determinantset/slaterdeterminant/determinants/downdet/size' : 200,
215        'simulation/qmcsystem/wavefunctions/psi0/determinantset/slaterdeterminant/determinants/downdet/sposet' : 'spo_d',
216        'simulation/qmcsystem/wavefunctions/psi0/determinantset/slaterdeterminant/determinants/updet/group' : 'u',
217        'simulation/qmcsystem/wavefunctions/psi0/determinantset/slaterdeterminant/determinants/updet/id' : 'updet',
218        'simulation/qmcsystem/wavefunctions/psi0/determinantset/slaterdeterminant/determinants/updet/size' : 200,
219        'simulation/qmcsystem/wavefunctions/psi0/determinantset/slaterdeterminant/determinants/updet/sposet' : 'spo_u',
220        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/O/coefficients/coeff' : np.array([
221            -1.488295706,-1.406709163,-1.232298155,-0.9391459067,-0.5575491618,-0.2186131788,-0.1463697747,-0.09781208605,-0.06418209044,-0.03977101442,-0.02226362717,-0.009458557456,-0.002401473122]),
222        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/O/coefficients/id' : 'eO',
223        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/O/coefficients/type' : 'Array',
224        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/O/cusp' : 0.0,
225        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/O/elementtype' : 'O',
226        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/O/rcut' : 6.05,
227        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/O/size' : 13,
228        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/V/coefficients/coeff' : np.array([
229            -2.88368129,-2.686350256,-2.500947608,-2.096756839,-1.444128943,-0.7686333881,-0.5720610092,-0.4061081504,-0.2772741837,-0.1767662649,-0.1010035901,-0.047325819,-0.01700847314]),
230        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/V/coefficients/id' : 'eV',
231        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/V/coefficients/type' : 'Array',
232        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/V/cusp' : 0.0,
233        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/V/elementtype' : 'V',
234        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/V/rcut' : 6.05,
235        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/correlations/V/size' : 13,
236        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/function' : 'bspline',
237        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/name' : 'J1',
238        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/print' : True,
239        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/source' : 'ion0',
240        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J1/type' : 'One-Body',
241        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/coefficients/coeff' : np.array([
242            0.529300758,0.3529320289,0.2365993762,0.1604582152,0.1128159005,0.08243318778,0.06023602184,0.04310552718,0.02984314449,0.01958170086,0.01186100803,0.006112206499,0.002625360754]),
243        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/coefficients/id' : 'ud',
244        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/coefficients/type' : 'Array',
245        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/rcut' : 6.05,
246        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/size' : 13,
247        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/speciesa' : 'u',
248        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/speciesb' : 'd',
249        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/coefficients/coeff' : np.array([
250            0.3569086717,0.2751683418,0.2058897032,0.1520886231,0.111693376,0.08181917929,0.05977972383,0.04283213009,0.02968150709,0.01944788064,0.01196129476,0.006271327336,0.002804432275]),
251        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/coefficients/id' : 'uu',
252        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/coefficients/type' : 'Array',
253        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/rcut' : 6.05,
254        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/size' : 13,
255        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/speciesa' : 'u',
256        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/speciesb' : 'u',
257        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/function' : 'bspline',
258        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/name' : 'J2',
259        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/print' : True,
260        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/type' : 'Two-Body',
261        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udO/coefficients/coeff' : np.array([
262            -0.004166620907,0.0003869059334,0.01344638104,-7.5215692e-05,-0.006436299048,0.0008791813519,0.007681280497,-0.006673633544,0.0300621195,0.00157665002,-0.001657156134,-0.01142258435,-0.02006687607,0.005271171591,0.01511417522,0.0008942941789,-0.002018984988,0.01595864928,0.005244762096,0.01545262066,-0.006397246289,-0.0072233246,-0.0008063061353,0.00830708478,0.001242024926,-0.0003962016339]),
263        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udO/coefficients/id' : 'udO',
264        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udO/coefficients/optimize' : True,
265        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udO/coefficients/type' : 'Array',
266        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udO/esize' : 3,
267        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udO/especies1' : 'u',
268        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udO/especies2' : 'd',
269        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udO/isize' : 3,
270        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udO/ispecies' : 'O',
271        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udO/rcut' : 5.0,
272        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udV/coefficients/coeff' : np.array([
273            0.000658573315,0.005924655484,0.008096696785,0.002998451182,0.001289481835,8.390092052e-05,0.0174934698,0.004082827829,0.001656608224,-0.01638865932,0.002852247319,-0.01043954065,0.006179637761,-0.000652977982,-0.004542989787,-0.0004825008427,0.03569269894,-0.01539236687,0.007843924995,-0.009660462887,-0.01173827315,0.005074028683,0.001248279616,0.008752252359,-0.003457347502,0.0001174638519]),
274        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udV/coefficients/id' : 'udV',
275        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udV/coefficients/optimize' : True,
276        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udV/coefficients/type' : 'Array',
277        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udV/esize' : 3,
278        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udV/especies1' : 'u',
279        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udV/especies2' : 'd',
280        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udV/isize' : 3,
281        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udV/ispecies' : 'V',
282        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/udV/rcut' : 5.0,
283        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuO/coefficients/coeff' : np.array([
284            -0.0006976974299,-0.001602461137,0.002262076236,-0.001250356792,-0.002453974076,0.00100226978,-0.008343708726,0.01062739293,0.01589135522,0.007887562739,-0.0005580320441,-0.01523126657,-0.009565046782,-0.0009005995139,0.01105399926,-0.0002575705031,-0.01652920678,0.00747060564,0.01464528142,0.005133083617,0.006916610617,-0.009683594066,0.001290999707,-0.001322800206,0.003931225142,-0.001163411737]),
285        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuO/coefficients/id' : 'uuO',
286        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuO/coefficients/optimize' : True,
287        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuO/coefficients/type' : 'Array',
288        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuO/esize' : 3,
289        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuO/especies1' : 'u',
290        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuO/especies2' : 'u',
291        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuO/isize' : 3,
292        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuO/ispecies' : 'O',
293        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuO/rcut' : 5.0,
294        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuV/coefficients/coeff' : np.array([
295            0.004388200165,0.001900643263,-0.01549468789,-0.002564479476,0.002118937653,0.0007437421471,-0.0085007067,0.009637603236,-0.01717900977,0.00186285366,-0.006121695671,0.01831402072,0.006890778761,0.003340289515,-0.001491823024,-0.001123033117,-0.008713157223,0.02100098414,-0.03224060809,-0.002479213835,0.001387768485,0.006636471962,0.0004745014561,0.001629700016,-0.001615344115,-0.0001680854702]),
296        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuV/coefficients/id' : 'uuV',
297        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuV/coefficients/optimize' : True,
298        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuV/coefficients/type' : 'Array',
299        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuV/esize' : 3,
300        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuV/especies1' : 'u',
301        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuV/especies2' : 'u',
302        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuV/isize' : 3,
303        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuV/ispecies' : 'V',
304        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/correlations/uuV/rcut' : 5.0,
305        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/function' : 'polynomial',
306        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/name' : 'J3',
307        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/print' : True,
308        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/source' : 'ion0',
309        'simulation/qmcsystem/wavefunctions/psi0/jastrows/J3/type' : 'eeI',
310        'simulation/qmcsystem/wavefunctions/psi0/name' : 'psi0',
311        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/href' : '../scf/pwscf_output/pwscf.pwscf.h5',
312        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/meshfactor' : 1.0,
313        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/precision' : 'float',
314        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/source' : 'ion0',
315        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/sposets/spo_d/name' : 'spo_d',
316        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/sposets/spo_d/size' : 200,
317        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/sposets/spo_d/spindataset' : 1,
318        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/sposets/spo_d/type' : 'bspline',
319        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/sposets/spo_u/name' : 'spo_u',
320        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/sposets/spo_u/size' : 200,
321        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/sposets/spo_u/spindataset' : 0,
322        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/sposets/spo_u/type' : 'bspline',
323        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/tilematrix' : np.array([
324            [2, 0, 0],
325            [0, 1, -1],
326            [0, 1, 1]]),
327        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/truncate' : False,
328        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/twistnum' : 0,
329        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/type' : 'bspline',
330        'simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/version' : 0.1,
331        'simulation/qmcsystem/wavefunctions/psi0/target' : 'e',
332        }
333
334    serial_references['VO2_M1_afm.in.xml'] = ref
335
336
337    # reference for generate/read
338    ref = ref.copy()
339    ref['simulation/project/application/name'] = 'qmcpack' # name has been updated
340    for k in list(ref.keys()):
341        if 'jastrow' in k or 'metadata' in k:
342            del ref[k]
343        #end if
344    #end for
345    #  generated initial jastrow rather than optimized one
346    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/coefficients/coeff'] = np.array([0.44140587,0.26944819,0.15547533,0.08413778,0.04227037,0.01951441,0.00820536,0.00312028])
347    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/coefficients/id'] = 'ud'
348    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/coefficients/type'] = 'Array'
349    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/rcut'] = 6.651925584744773
350    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/size'] = 8
351    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/speciesa'] = 'u'
352    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/ud/speciesb'] = 'd'
353    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/coefficients/coeff'] = np.array([0.31314348,0.21502161,0.13496763,0.07727679,0.04023251,0.01897712,0.00807963,0.00309418])
354    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/coefficients/id'] = 'uu'
355    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/coefficients/type'] = 'Array'
356    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/rcut'] = 6.651925584744773
357    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/size'] = 8
358    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/speciesa'] = 'u'
359    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/correlations/uu/speciesb'] = 'u'
360    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/function'] = 'bspline'
361    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/name'] = 'J2'
362    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/print'] = True
363    ref['simulation/qmcsystem/wavefunctions/psi0/jastrows/J2/type'] = 'Two-Body'
364
365    serial_references['VO2_M1_afm.in.xml gen_read'] = ref
366
367
368    # reference for generate
369    ref = ref.copy()
370    ref['simulation/qmcsystem/simulationcell/bconds'] = tuple('ppp')
371    for k in list(ref.keys()):
372        if 'SpinDensity' in k:
373            del ref[k]
374        #end if
375    #end for
376    ref['simulation/project/application/version'] = '1.0'
377    ref['simulation/qmcsystem/wavefunctions/psi0/sposet_builders/bspline/version'] = '0.10'
378    ref['simulation/qmcsystem/hamiltonians/h0/estimators/0/grid'] = (72, 44, 44)
379    ref['simulation/qmcsystem/hamiltonians/h0/estimators/0/name'] = 'SpinDensity'
380    ref['simulation/qmcsystem/hamiltonians/h0/estimators/0/type'] = 'spindensity'
381
382    serial_references['VO2_M1_afm.in.xml gen'] = ref
383
384
385    ref = {
386        'simulation/afqmcinfo/naea' : 5,
387        'simulation/afqmcinfo/naeb' : 5,
388        'simulation/afqmcinfo/name' : 'info0',
389        'simulation/afqmcinfo/nmo' : 9,
390        'simulation/execute/blocks' : 1000,
391        'simulation/execute/estimator/block_size' : 2,
392        'simulation/execute/estimator/name' : 'back_propagation',
393        'simulation/execute/estimator/naverages' : 4,
394        'simulation/execute/estimator/nsteps' : 200,
395        'simulation/execute/estimator/onerdm' : onerdm(),
396        'simulation/execute/estimator/ortho' : 1,
397        'simulation/execute/ham' : 'ham0',
398        'simulation/execute/info' : 'info0',
399        'simulation/execute/ncores' : 1,
400        'simulation/execute/nwalkers' : 10,
401        'simulation/execute/prop' : 'prop0',
402        'simulation/execute/steps' : 10,
403        'simulation/execute/timestep' : 0.01,
404        'simulation/execute/wfn' : 'wfn0',
405        'simulation/execute/wset' : 'wset0',
406        'simulation/hamiltonian/filename' : 'afqmc.h5',
407        'simulation/hamiltonian/filetype' : 'hdf5',
408        'simulation/hamiltonian/info' : 'info0',
409        'simulation/hamiltonian/name' : 'ham0',
410        'simulation/method' : 'afqmc',
411        'simulation/project/id' : 'qmc',
412        'simulation/project/series' : 0,
413        'simulation/propagator/hybrid' : 'yes',
414        'simulation/propagator/info' : 'info0',
415        'simulation/propagator/name' : 'prop0',
416        'simulation/random/seed' : 7,
417        'simulation/walkerset/name' : 'wset0',
418        'simulation/walkerset/type' : 'shared',
419        'simulation/walkerset/walker_type' : 'CLOSED',
420        'simulation/wavefunction/cutoff' : 1e-08,
421        'simulation/wavefunction/filename' : 'afqmc.h5',
422        'simulation/wavefunction/filetype' : 'hdf5',
423        'simulation/wavefunction/info' : 'info0',
424        'simulation/wavefunction/name' : 'wfn0',
425        'simulation/wavefunction/type' : 'NOMSD',
426        }
427
428
429    serial_references['CH4_afqmc.in.xml read'] = ref
430
431    ref = ref.copy()
432    serial_references['CH4_afqmc.in.xml write'] = ref
433
434    ref = ref.copy()
435    for k in list(ref.keys()):
436        if 'estimator' in k:
437            del ref[k]
438        #end if
439    #end for
440    ref['simulation/execute/estimators/back_propagation/block_size'] = 2
441    ref['simulation/execute/estimators/back_propagation/name'] = 'back_propagation'
442    ref['simulation/execute/estimators/back_propagation/naverages'] = 4
443    ref['simulation/execute/estimators/back_propagation/nsteps'] = 200
444    ref['simulation/execute/estimators/back_propagation/onerdm'] = onerdm()
445    ref['simulation/execute/estimators/back_propagation/ortho'] = 1
446    ref['simulation/propagator/hybrid'] = True
447    serial_references['CH4_afqmc.in.xml compose'] = ref
448
449    ref = ref.copy()
450    serial_references['CH4_afqmc.in.xml gen est'] = ref
451
452    ref = ref.copy()
453    del ref['simulation/random/seed']
454    del ref['simulation/afqmcinfo/naea']
455    del ref['simulation/afqmcinfo/naeb']
456    del ref['simulation/afqmcinfo/nmo']
457    ref['simulation/hamiltonian/filename'] = 'MISSING.h5'
458    ref['simulation/wavefunction/filename'] = 'MISSING.h5'
459    ref['simulation/execute/blocks'] = 10000
460    ref['simulation/execute/timestep'] = 0.005
461    for k in list(ref.keys()):
462        if 'estimator' in k:
463            del ref[k]
464        #end if
465    #end for
466    serial_references['CH4_afqmc.in.xml gen empty'] = ref
467
468#end def generate_serial_references
469
470
471def get_serial_references():
472    if len(serial_references)==0:
473        generate_serial_references()
474    #end if
475    return serial_references
476#end def get_serial_references
477
478
479def check_vs_serial_reference(qi,name):
480    sr = get_serial_references()[name]
481    assert(len(sr)>0)
482    sq = qi.serial()
483    extra = set(sq.keys())-set(sr.keys())
484    for k in extra:
485        if not k.startswith('_metadata'):
486            print(k)
487        #end if
488        assert(k.startswith('_metadata'))
489    #end for
490    for k in sorted(sr.keys()):
491        if k not in sq:
492            print(k)
493        elif not value_eq(sq[k],sr[k]):
494            print(k)
495            print(sr[k])
496            print(sq[k])
497        #end if
498        assert(k in sq)
499        assert(value_eq(sq[k],sr[k]))
500    #end for
501#end def check_vs_serial_reference
502
503
504
505def test_files():
506    filenames = [
507        'VO2_M1_afm.in.xml',
508        'CH4_afqmc.in.xml',
509        ]
510    files = get_files()
511    assert(set(filenames)==set(files.keys()))
512#end def test_files
513
514
515
516def test_import():
517    from qmcpack_input import QmcpackInput
518    from qmcpack_input import simulation,meta,section
519#end def test_import
520
521
522
523def test_qixml_class_init():
524    from generic import obj
525    from qmcpack_input import classes
526
527    attr_types = obj(
528        tag            = str,
529        identifier     = (str,tuple),
530        attributes     = list,
531        elements       = list,
532        text           = str,
533        parameters     = list,
534        attribs        = list,
535        costs          = list,
536        h5tags         = list,
537        types          = obj,
538        write_types    = obj,
539        attr_types     = obj,
540        precision      = str,
541        defaults       = obj,
542        collection_id  = str,
543        exp_names      = obj,
544        params         = list,
545        plurals_inv    = obj,
546        plurals        = obj,
547        expanded_names = obj,
548        afqmc_order    = list,
549        )
550    optional = set(['expanded_names','afqmc_order'])
551    assert(len(attr_types)==21)
552
553    def valid_name(s):
554        v = True
555        v &= isinstance(s,str)
556        v &= ' ' not in s and '-' not in s
557        v &= s.lower()==s
558        return v
559    #end def valid_name
560
561    for cls in classes:
562        c = obj()
563        d = cls.__dict__
564        for k,v in d.items():
565            if not k.startswith('__'):
566                c[k] = v
567            #end if
568        #end for
569        for name,type in attr_types.items():
570            if name not in optional:
571                assert(name in c)
572            #end if
573            if name in c:
574                v = c[name]
575                if v is not None:
576                    assert(isinstance(v,type))
577                    if isinstance(v,str):
578                        assert(valid_name(v))
579                    elif isinstance(v,list):
580                        for vv in v:
581                            assert(valid_name(vv) or vv=='atomic-number')
582                        #end for
583                    #end if
584                #end if
585            #end if
586        #end for
587    #end for
588
589#end def test_qixml_class_init
590
591
592
593def test_compose():
594    import numpy as np
595    from generic import obj
596    from qmcpack_input import QmcpackInput
597    from qmcpack_input import simulation,meta,section
598
599    qi_comp = QmcpackInput(
600        meta(
601            lattice  = obj(units='bohr'),
602            position = obj(condition='0',datatype='posArray'),
603            ),
604        simulation(
605            project = section(
606                id     ='qmc',
607                series = 0,
608                application = section(
609                    name    = 'qmcapp',
610                    role    = 'molecu',
611                    class_  = 'serial',
612                    version = 1.0,
613                    ),
614                ),
615            qmcsystem = section(
616                simulationcell = section(
617                    lattice = np.array(
618                        [[ 21.73940944, 0.00000000,  0.00000000],
619                         [  5.48695844, 8.57519925, -8.56456075],
620                         [ -5.48695844, 8.57519925,  8.56456075]]),
621                    bconds = np.array(tuple('ppp')),
622                    lr_dim_cutoff = 15,
623                    ),
624                particlesets = [
625                    section(
626                        name = 'e',
627                        random = True,
628                        groups = [
629                            section(
630                                name   = 'u',
631                                size   = 200,
632                                charge = -1,
633                                mass   = 1.0,
634                                ),
635                            section(
636                                name   = 'd',
637                                size   = 200,
638                                charge = -1,
639                                mass   = 1.0,
640                                ),
641                            ],
642                        ),
643                    section(
644                        name = 'ion0',
645                        groups = [
646                            section(
647                                name         = 'V',
648                                size         = 16,
649                                charge       = 13,
650                                valence      = 13,
651                                atomicnumber = 23,
652                                mass         = 92861.5851912,
653                                position     = np.array([
654                                    [ 2.45778327,  8.39460555,  0.22661828],
655                                    [ 8.41192147,  8.75579295, -0.22661828],
656                                    [ 5.20126250, 13.04339257, -4.05566210],
657                                    [ 5.66844224,  4.10700593,  4.05566210],
658                                    [13.32748799,  8.39460555,  0.22661828],
659                                    [19.28162619,  8.75579295, -0.22661828],
660                                    [16.07096722, 13.04339257, -4.05566210],
661                                    [16.53814696,  4.10700593,  4.05566210],
662                                    [ 7.94474171,  8.39460555, -8.33794247],
663                                    [ 2.92496303,  8.75579295,  8.33794247],
664                                    [ 5.20126250,  4.46819332, -4.05566210],
665                                    [ 5.66844224, 12.68220518,  4.05566210],
666                                    [18.81444643,  8.39460555, -8.33794247],
667                                    [13.79466775,  8.75579295,  8.33794247],
668                                    [16.07096722,  4.46819332, -4.05566210],
669                                    [16.53814696, 12.68220518,  4.05566210]
670                                    ]),
671                                ),
672                            section(
673                                name         = 'O',
674                                size         = 32,
675                                charge       = 6,
676                                valence      = 6,
677                                atomicnumber = 8,
678                                mass         = 29164.3928678,
679                                position     = np.array([
680                                    [ 0.00978311,  1.81708472,  1.78656736],
681                                    [10.85992161, 15.33331378, -1.78656738],
682                                    [ 2.75326234, 11.04571415, -2.49571300],
683                                    [ 8.11644240,  6.10468435,  2.49571300],
684                                    [ 2.71381355,  6.02493499,  2.55909075],
685                                    [ 8.15589117, 11.12546351, -2.55909075],
686                                    [ 5.45729278, 15.41306313, -1.72318961],
687                                    [ 5.41241194,  1.73733537,  1.72318961],
688                                    [10.87948783,  1.81708472,  1.78656736],
689                                    [21.72962633, 15.33331378, -1.78656738],
690                                    [13.62296706, 11.04571415, -2.49571300],
691                                    [18.98614712,  6.10468435,  2.49571300],
692                                    [13.58351827,  6.02493499,  2.55909075],
693                                    [19.02559589, 11.12546351, -2.55909075],
694                                    [16.32699750, 15.41306313, -1.72318961],
695                                    [16.28211666,  1.73733537,  1.72318961],
696                                    [ 0.00978311, 10.39228397,  1.78656736],
697                                    [10.85992161,  6.75811453, -1.78656738],
698                                    [-2.73369610, 11.04571415,  6.06884775],
699                                    [13.60340084,  6.10468435, -6.06884775],
700                                    [ 8.20077199,  6.02493499, -6.00547000],
701                                    [ 2.66893273, 11.12546351,  6.00547000],
702                                    [ 5.45729278,  6.83786388, -1.72318961],
703                                    [ 5.41241194, 10.31253462,  1.72318961],
704                                    [10.87948783, 10.39228397,  1.78656736],
705                                    [21.72962633,  6.75811453, -1.78656738],
706                                    [ 8.13600862, 11.04571415,  6.06884775],
707                                    [24.47310556,  6.10468435, -6.06884775],
708                                    [19.07047671,  6.02493499, -6.00547000],
709                                    [13.53863745, 11.12546351,  6.00547000],
710                                    [16.32699750,  6.83786388, -1.72318961],
711                                    [16.28211666, 10.31253462,  1.72318961]
712                                    ]),
713                                ),
714                            ],
715                        ),
716                    ],
717                wavefunction = section(
718                    name   = 'psi0',
719                    target = 'e',
720                    sposet_builder = section(
721                        type       = 'bspline',
722                        href       = '../scf/pwscf_output/pwscf.pwscf.h5',
723                        tilematrix = np.array([[2,0,0],
724                                               [0,1,-1],
725                                               [0,1,1]]),
726                        twistnum   = 0,
727                        source     = 'ion0',
728                        version    = 0.10,
729                        meshfactor = 1.0,
730                        precision  = 'float',
731                        truncate   = False,
732                        sposets = [
733                            section(
734                                type        = 'bspline',
735                                name        = 'spo_u',
736                                size        = 200,
737                                spindataset = 0,
738                                ),
739                            section(
740                                type        = 'bspline',
741                                name        = 'spo_d',
742                                size        = 200,
743                                spindataset = 1,
744                                )
745                            ],
746                        ),
747                    determinantset = section(
748                        slaterdeterminant = section(
749                            determinants = [
750                                section(
751                                    id     = 'updet',
752                                    group  = 'u',
753                                    sposet = 'spo_u',
754                                    size   = 200,
755                                    ),
756                                section(
757                                    id     = 'downdet',
758                                    group  = 'd',
759                                    sposet = 'spo_d',
760                                    size   = 200,
761                                    ),
762                                ],
763                            ),
764                        ),
765                    jastrows = [
766                        section(
767                            type     = 'One-Body',
768                            name     = 'J1',
769                            function = 'bspline',
770                            source   = 'ion0',
771                            print    = True,
772                            correlations = [
773                                section(
774                                    elementType = 'O',
775                                    size        = 13,
776                                    rcut        = 6.05,
777                                    cusp        = 0.0,
778                                    coefficients = section(
779                                        id   = 'eO',
780                                        type = 'Array',
781                                        coeff = np.array([
782                                            -1.488295706, -1.406709163,
783                                            -1.232298155, -0.9391459067,
784                                            -0.5575491618, -0.2186131788,
785                                            -0.1463697747, -0.09781208605,
786                                            -0.06418209044, -0.03977101442,
787                                            -0.02226362717, -0.009458557456,
788                                            -0.002401473122])
789                                        ),
790                                    ),
791                                section(
792                                    elementType = 'V',
793                                    size        = 13,
794                                    rcut        = 6.05,
795                                    cusp        = 0.0,
796                                    coefficients = section(
797                                        id   = 'eV',
798                                        type = 'Array',
799                                        coeff = np.array([
800                                            -2.88368129, -2.686350256,
801                                            -2.500947608, -2.096756839,
802                                            -1.444128943, -0.7686333881,
803                                            -0.5720610092, -0.4061081504,
804                                            -0.2772741837, -0.1767662649,
805                                            -0.1010035901, -0.047325819,
806                                            -0.01700847314])
807                                        ),
808                                    ),
809                                ],
810                            ),
811                        section(
812                            type     = 'Two-Body',
813                            name     = 'J2',
814                            function = 'bspline',
815                            print    = True,
816                            correlations = [
817                                section(
818                                    speciesA    = 'u',
819                                    speciesB    = 'u',
820                                    size        = 13,
821                                    rcut        = 6.05,
822                                    coefficients = section(
823                                        id    = 'uu',
824                                        type  = 'Array',
825                                        coeff = np.array([
826                                            0.3569086717, 0.2751683418,
827                                            0.2058897032, 0.1520886231,
828                                            0.111693376, 0.08181917929,
829                                            0.05977972383, 0.04283213009,
830                                            0.02968150709, 0.01944788064,
831                                            0.01196129476, 0.006271327336,
832                                            0.002804432275])
833                                        ),
834                                    ),
835                                section(
836                                    speciesA    = 'u',
837                                    speciesB    = 'd',
838                                    size        = 13,
839                                    rcut        = 6.05,
840                                    coefficients = section(
841                                        id    = 'ud',
842                                        type  = 'Array',
843                                        coeff = np.array([
844                                            0.529300758, 0.3529320289,
845                                            0.2365993762, 0.1604582152,
846                                            0.1128159005, 0.08243318778,
847                                            0.06023602184, 0.04310552718,
848                                            0.02984314449, 0.01958170086,
849                                            0.01186100803, 0.006112206499,
850                                            0.002625360754])
851                                        ),
852                                    ),
853                                ],
854                            ),
855                        section(
856                            type     = 'eeI',
857                            name     = 'J3',
858                            function = 'polynomial',
859                            print    = True,
860                            source   = 'ion0',
861                            correlations = [
862                                section(
863                                    ispecies = 'O',
864                                    especies1= 'u',
865                                    especies2= 'u',
866                                    isize    = 3,
867                                    esize    = 3,
868                                    rcut     = 5.0,
869                                    coefficients = section(
870                                        id       = 'uuO',
871                                        type     = 'Array',
872                                        optimize = True,
873                                        coeff    = np.array([
874                                            -0.0006976974299, -0.001602461137,
875                                            0.002262076236, -0.001250356792,
876                                            -0.002453974076, 0.00100226978,
877                                            -0.008343708726, 0.01062739293,
878                                            0.01589135522, 0.007887562739,
879                                            -0.0005580320441, -0.01523126657,
880                                            -0.009565046782, -0.0009005995139,
881                                            0.01105399926, -0.0002575705031,
882                                            -0.01652920678, 0.00747060564,
883                                            0.01464528142, 0.005133083617,
884                                            0.006916610617, -0.009683594066,
885                                            0.001290999707, -0.001322800206,
886                                            0.003931225142, -0.001163411737])
887                                        ),
888                                    ),
889                                section(
890                                    ispecies = 'O',
891                                    especies1= 'u',
892                                    especies2= 'd',
893                                    isize    = 3,
894                                    esize    = 3,
895                                    rcut     = 5.0,
896                                    coefficients = section(
897                                        id       = 'udO',
898                                        type     = 'Array',
899                                        optimize = True,
900                                        coeff    = np.array([
901                                            -0.004166620907, 0.0003869059334,
902                                            0.01344638104, -7.5215692e-05,
903                                            -0.006436299048, 0.0008791813519,
904                                            0.007681280497, -0.006673633544,
905                                            0.0300621195, 0.00157665002,
906                                            -0.001657156134, -0.01142258435,
907                                            -0.02006687607, 0.005271171591,
908                                            0.01511417522, 0.0008942941789,
909                                            -0.002018984988, 0.01595864928,
910                                            0.005244762096, 0.01545262066,
911                                            -0.006397246289, -0.0072233246,
912                                            -0.0008063061353, 0.00830708478,
913                                            0.001242024926, -0.0003962016339])
914                                        ),
915                                    ),
916                                section(
917                                    ispecies = 'V',
918                                    especies1= 'u',
919                                    especies2= 'u',
920                                    isize    = 3,
921                                    esize    = 3,
922                                    rcut     = 5.0,
923                                    coefficients = section(
924                                        id       = 'uuV',
925                                        type     = 'Array',
926                                        optimize = True,
927                                        coeff    = np.array([
928                                            0.004388200165, 0.001900643263,
929                                            -0.01549468789, -0.002564479476,
930                                            0.002118937653, 0.0007437421471,
931                                            -0.0085007067, 0.009637603236,
932                                            -0.01717900977, 0.00186285366,
933                                            -0.006121695671, 0.01831402072,
934                                            0.006890778761, 0.003340289515,
935                                            -0.001491823024, -0.001123033117,
936                                            -0.008713157223, 0.02100098414,
937                                            -0.03224060809, -0.002479213835,
938                                            0.001387768485, 0.006636471962,
939                                            0.0004745014561, 0.001629700016,
940                                            -0.001615344115, -0.0001680854702])
941                                        ),
942                                    ),
943                                section(
944                                    ispecies = 'V',
945                                    especies1= 'u',
946                                    especies2= 'd',
947                                    isize    = 3,
948                                    esize    = 3,
949                                    rcut     = 5.0,
950                                    coefficients = section(
951                                        id       = 'udV',
952                                        type     = 'Array',
953                                        optimize = True,
954                                        coeff    = np.array([
955                                            0.000658573315, 0.005924655484,
956                                            0.008096696785, 0.002998451182,
957                                            0.001289481835, 8.390092052e-05,
958                                            0.0174934698, 0.004082827829,
959                                            0.001656608224, -0.01638865932,
960                                            0.002852247319, -0.01043954065,
961                                            0.006179637761, -0.000652977982,
962                                            -0.004542989787, -0.0004825008427,
963                                            0.03569269894, -0.01539236687,
964                                            0.007843924995, -0.009660462887,
965                                            -0.01173827315, 0.005074028683,
966                                            0.001248279616, 0.008752252359,
967                                            -0.003457347502, 0.0001174638519])
968                                        ),
969                                    ),
970                                ],
971                            ),
972                        ],
973                    ),
974                hamiltonian = section(
975                    name   = 'h0',
976                    type   = 'generic',
977                    target = 'e',
978                    pairpots = [
979                        section(
980                            type   = 'coulomb',
981                            name   = 'ElecElec',
982                            source = 'e',
983                            target = 'e'
984                            ),
985                        section(
986                            type   = 'coulomb',
987                            name   = 'IonIon',
988                            source = 'ion0',
989                            target = 'ion0'
990                            ),
991                        section(
992                            type         = 'pseudo',
993                            name         = 'PseudoPot',
994                            source       = 'ion0',
995                            wavefunction = 'psi0',
996                            format       = 'xml',
997                            pseudos = [
998                                section(
999                                    elementType = 'O',
1000                                    href        = 'O.opt.xml'
1001                                    ),
1002                                section(
1003                                    elementType = 'V',
1004                                    href        = 'V.opt.xml'
1005                                    ),
1006                                ]
1007                            ),
1008                        section(
1009                            type     = 'MPC',
1010                            name     = 'MPC',
1011                            source   = 'e',
1012                            target   = 'e',
1013                            ecut     = 60.0,
1014                            physical = False
1015                            )
1016                        ],
1017                    estimators = [
1018                        section(
1019                            type = 'spindensity',
1020                            name = 'SpinDensity',
1021                            grid = np.array([72,44,44]),
1022                            ),
1023                        section(
1024                            name   = 'KEcorr',
1025                            type   = 'chiesa',
1026                            source = 'e',
1027                            psi    = 'psi0'
1028                            )
1029                        ],
1030                    )
1031                ),
1032            calculations = [
1033                section(
1034                    method           = 'vmc',
1035                    move             = 'pbyp',
1036                    checkpoint       = -1,
1037                    walkers          = 1,
1038                    blocks           = 70,
1039                    steps            = 5,
1040                    substeps         = 2,
1041                    timestep         = 0.3,
1042                    warmupsteps      = 20,
1043                    samplesperthread = 2,
1044                    ),
1045                section(
1046                    method           = 'dmc',
1047                    move             = 'pbyp',
1048                    checkpoint       = -1,
1049                    blocks           = 80,
1050                    steps            = 5,
1051                    timestep         = 0.02,
1052                    nonlocalmoves    = 'yes',
1053                    warmupsteps      = 2,
1054                    ),
1055                section(
1056                    method           = 'dmc',
1057                    move             = 'pbyp',
1058                    checkpoint       = -1,
1059                    blocks           = 600,
1060                    steps            = 5,
1061                    timestep         = 0.005,
1062                    nonlocalmoves    = 'yes',
1063                    warmupsteps      = 10,
1064                    ),
1065                ],
1066            ),
1067        )
1068    qi_comp.pluralize()
1069
1070    check_vs_serial_reference(qi_comp,'VO2_M1_afm.in.xml')
1071
1072
1073    qi_afqmc = QmcpackInput(
1074        meta(),
1075        simulation(
1076            method = 'afqmc',
1077            project = section(
1078                id     = 'qmc',
1079                series = 0,
1080                ),
1081            random = section(
1082                seed = 7
1083                ),
1084            afqmcinfo = section(
1085                name = 'info0',
1086                nmo  = 9,
1087                naea = 5,
1088                naeb = 5,
1089                ),
1090            hamiltonian = section(
1091                name     = 'ham0',
1092                info     = 'info0',
1093                filetype = 'hdf5',
1094                filename = 'afqmc.h5',
1095                ),
1096            wavefunction = section(
1097                type     = 'NOMSD',
1098                name     = 'wfn0',
1099                info     = 'info0',
1100                filetype = 'hdf5',
1101                filename = 'afqmc.h5',
1102                cutoff   = 1e-8,
1103                ),
1104            walkerset = section(
1105                type        = 'shared',
1106                name        = 'wset0',
1107                walker_type = 'CLOSED',
1108                ),
1109            propagator = section(
1110                name   = 'prop0',
1111                info   = 'info0',
1112                hybrid = True,
1113                ),
1114            execute = section(
1115                info     = 'info0',
1116                ham      = 'ham0',
1117                wfn      = 'wfn0',
1118                wset     = 'wset0',
1119                prop     = 'prop0',
1120                blocks   = 1000,
1121                timestep = 0.01,
1122                steps    = 10,
1123                ncores   = 1,
1124                nwalkers = 10,
1125                estimators = [
1126                    section(
1127                        name       = 'back_propagation',
1128                        naverages  = 4,
1129                        block_size = 2,
1130                        ortho      = 1,
1131                        nsteps     = 200,
1132                        onerdm     = section(),
1133                        )
1134                    ],
1135                ),
1136            )
1137        )
1138
1139    check_vs_serial_reference(qi_afqmc,'CH4_afqmc.in.xml compose')
1140
1141#end def test_compose
1142
1143
1144
1145def test_generate():
1146    import numpy as np
1147    from physical_system import generate_physical_system
1148    from qmcpack_input import generate_qmcpack_input,spindensity
1149    from qmcpack_input import back_propagation,onerdm
1150
1151    system = generate_physical_system(
1152        units    = 'A',
1153        axes     = '''
1154                    5.75200000    0.00000000    0.00000000
1155                    0.00000000    4.53780000    0.00000000
1156                   -2.90357335    0.00000000    4.53217035
1157                   ''',
1158        elem_pos = '''
1159                   V   1.30060289    4.44223393    0.11992123
1160                   V   1.54782377    0.09556607    4.41224912
1161                   V  -0.15118378    2.36446607    2.38600640
1162                   V   2.99961044    2.17333393    2.14616395
1163                   O   0.00517700    0.96155982    0.94541073
1164                   O   2.84324965    3.57624018    3.58675961
1165                   O  -1.44660967    1.30734018    3.21149591
1166                   O   4.29503633    3.23045982    1.32067444
1167                   O   1.43608828    3.18825828    1.35421250
1168                   O   1.41233837    1.34954172    3.17795785
1169                   O  -0.01569839    3.61844172    3.62029768
1170                   O   2.86412504    0.91935828    0.91187267
1171                   ''',
1172        tiling = [[ 2,  0,  0],
1173                  [ 0,  1, -1],
1174                  [ 0,  1,  1]],
1175        V = 13,
1176        O = 6,
1177        )
1178
1179    tile_pos = np.array([
1180        [ 1.30060289e+00,  4.44223393e+00,  1.19921230e-01],
1181        [ 4.45139712e+00,  4.63336607e+00, -1.19921230e-01],
1182        [ 2.75238957e+00,  6.90226607e+00, -2.14616395e+00],
1183        [ 2.99961044e+00,  2.17333393e+00,  2.14616395e+00],
1184        [ 5.17700000e-03,  9.61559820e-01,  9.45410730e-01],
1185        [ 5.74682300e+00,  8.11404018e+00, -9.45410740e-01],
1186        [ 1.45696368e+00,  5.84514018e+00, -1.32067444e+00],
1187        [ 4.29503633e+00,  3.23045982e+00,  1.32067444e+00],
1188        [ 1.43608828e+00,  3.18825828e+00,  1.35421250e+00],
1189        [ 4.31591172e+00,  5.88734172e+00, -1.35421250e+00],
1190        [ 2.88787496e+00,  8.15624172e+00, -9.11872670e-01],
1191        [ 2.86412504e+00,  9.19358280e-01,  9.11872670e-01],
1192        [ 7.05260289e+00,  4.44223393e+00,  1.19921230e-01],
1193        [ 1.02033971e+01,  4.63336607e+00, -1.19921230e-01],
1194        [ 8.50438957e+00,  6.90226607e+00, -2.14616395e+00],
1195        [ 8.75161044e+00,  2.17333393e+00,  2.14616395e+00],
1196        [ 5.75717700e+00,  9.61559820e-01,  9.45410730e-01],
1197        [ 1.14988230e+01,  8.11404018e+00, -9.45410740e-01],
1198        [ 7.20896368e+00,  5.84514018e+00, -1.32067444e+00],
1199        [ 1.00470363e+01,  3.23045982e+00,  1.32067444e+00],
1200        [ 7.18808828e+00,  3.18825828e+00,  1.35421250e+00],
1201        [ 1.00679117e+01,  5.88734172e+00, -1.35421250e+00],
1202        [ 8.63987496e+00,  8.15624172e+00, -9.11872670e-01],
1203        [ 8.61612504e+00,  9.19358280e-01,  9.11872670e-01],
1204        [ 4.20417624e+00,  4.44223393e+00, -4.41224912e+00],
1205        [ 1.54782377e+00,  4.63336607e+00,  4.41224912e+00],
1206        [ 2.75238957e+00,  2.36446607e+00, -2.14616395e+00],
1207        [ 2.99961044e+00,  6.71113393e+00,  2.14616395e+00],
1208        [ 5.17700000e-03,  5.49935982e+00,  9.45410730e-01],
1209        [ 5.74682300e+00,  3.57624018e+00, -9.45410740e-01],
1210        [-1.44660967e+00,  5.84514018e+00,  3.21149591e+00],
1211        [ 7.19860968e+00,  3.23045982e+00, -3.21149591e+00],
1212        [ 4.33966163e+00,  3.18825828e+00, -3.17795785e+00],
1213        [ 1.41233837e+00,  5.88734172e+00,  3.17795785e+00],
1214        [ 2.88787496e+00,  3.61844172e+00, -9.11872670e-01],
1215        [ 2.86412504e+00,  5.45715828e+00,  9.11872670e-01],
1216        [ 9.95617624e+00,  4.44223393e+00, -4.41224912e+00],
1217        [ 7.29982377e+00,  4.63336607e+00,  4.41224912e+00],
1218        [ 8.50438957e+00,  2.36446607e+00, -2.14616395e+00],
1219        [ 8.75161044e+00,  6.71113393e+00,  2.14616395e+00],
1220        [ 5.75717700e+00,  5.49935982e+00,  9.45410730e-01],
1221        [ 1.14988230e+01,  3.57624018e+00, -9.45410740e-01],
1222        [ 4.30539033e+00,  5.84514018e+00,  3.21149591e+00],
1223        [ 1.29506097e+01,  3.23045982e+00, -3.21149591e+00],
1224        [ 1.00916616e+01,  3.18825828e+00, -3.17795785e+00],
1225        [ 7.16433837e+00,  5.88734172e+00,  3.17795785e+00],
1226        [ 8.63987496e+00,  3.61844172e+00, -9.11872670e-01],
1227        [ 8.61612504e+00,  5.45715828e+00,  9.11872670e-01]],dtype=float)
1228
1229    s = system.structure
1230    if not value_eq(s.pos,tile_pos):
1231        tile_elem = np.array([
1232            'V','V','V','V','O','O','O','O','O','O','O','O',
1233            'V','V','V','V','O','O','O','O','O','O','O','O',
1234            'V','V','V','V','O','O','O','O','O','O','O','O',
1235            'V','V','V','V','O','O','O','O','O','O','O','O'],dtype=object)
1236        s.pos  = tile_pos
1237        s.elem = tile_elem
1238    #end if
1239
1240    #system.structure.order_by_species()
1241
1242    qi = generate_qmcpack_input(
1243        input_type      = 'basic',
1244        system          = system,
1245        pseudos         = ['V.opt.xml','O.opt.xml'],
1246        spin_polarized  = True,
1247        twistnum        = 0,
1248        orbitals_h5     = '../scf/pwscf_output/pwscf.pwscf.h5',
1249        estimators      = [spindensity(grid=(72,44,44))],
1250        qmc = 'dmc',
1251        # vmc inputs
1252        vmc_walkers     = 1,
1253        vmc_warmupsteps = 20,
1254        vmc_blocks      = 70,
1255        vmc_steps       = 5,
1256        vmc_substeps    = 2,
1257        vmc_timestep    = 0.3,
1258        vmc_samplesperthread = 2,
1259        # dmc inputs
1260        eq_dmc          = True,
1261        eq_warmupsteps  = 2,
1262        eq_blocks       = 80,
1263        eq_steps        =  5,
1264        eq_timestep     = 0.02,
1265        # dmc inputs
1266        warmupsteps     = 10,
1267        blocks          = 600,
1268        steps           =  5,
1269        timestep        = 0.005,
1270        nonlocalmoves   = 'yes',
1271        )
1272
1273    qi.pluralize()
1274
1275    check_vs_serial_reference(qi,'VO2_M1_afm.in.xml gen')
1276
1277
1278    # test afqmc
1279    qi = generate_qmcpack_input(
1280        input_type = 'basic_afqmc',
1281        )
1282    check_vs_serial_reference(qi,'CH4_afqmc.in.xml gen empty')
1283
1284    qi = generate_qmcpack_input(
1285        input_type = 'basic_afqmc',
1286        seed       = 7,
1287        nmo        = 9,
1288        naea       = 5,
1289        naeb       = 5,
1290        ham_file   = 'afqmc.h5',
1291        blocks     = 1000,
1292        timestep   = 0.01,
1293        estimators = [
1294            back_propagation(
1295                naverages  = 4,
1296                block_size = 2,
1297                ortho      = 1,
1298                nsteps     = 200,
1299                onerdm     = onerdm(),
1300                ),
1301            ],
1302        )
1303
1304    check_vs_serial_reference(qi,'CH4_afqmc.in.xml gen est')
1305
1306#end def test_generate
1307
1308
1309
1310def test_read():
1311    from qmcpack_input import QmcpackInput
1312
1313    files = get_files()
1314
1315    qi_read = QmcpackInput(files['VO2_M1_afm.in.xml'])
1316    assert(not qi_read.is_afqmc_input())
1317    qi_read.pluralize()
1318    assert(not qi_read.is_afqmc_input())
1319
1320    # remove extraneous data members for purpose of comparison
1321    del qi_read._metadata.spo_u
1322    del qi_read._metadata.spo_d
1323    spob = qi_read.simulation.qmcsystem.wavefunctions.psi0.sposet_builders
1324    sposets = spob.bspline.sposets
1325    del sposets.spo_u.spos
1326    del sposets.spo_d.spos
1327
1328    check_vs_serial_reference(qi_read,'VO2_M1_afm.in.xml')
1329
1330
1331    # test read for afqmc input file
1332    qi = QmcpackInput(files['CH4_afqmc.in.xml'])
1333    assert(qi.is_afqmc_input())
1334
1335    check_vs_serial_reference(qi,'CH4_afqmc.in.xml read')
1336
1337#end def test_read
1338
1339
1340
1341def test_write():
1342    import os
1343    from qmcpack_input import QmcpackInput
1344
1345    tpath = testing.setup_unit_test_output_directory('qmcpack_input','test_write')
1346
1347    files = get_files()
1348
1349    # test write real space qmc input file
1350    ref_file   = 'VO2_M1_afm.in.xml'
1351    write_file = os.path.join(tpath,'write_'+ref_file)
1352
1353    qi_read = QmcpackInput(files[ref_file])
1354
1355    text = qi_read.write()
1356    assert('<simulation>' in text)
1357    assert('<project' in text)
1358    assert('<application' in text)
1359    assert('<qmcsystem>' in text)
1360    assert('<simulationcell>' in text)
1361    assert('<particleset' in text)
1362    assert('<group' in text)
1363    assert('<attrib' in text)
1364    assert('<wavefunction' in text)
1365    assert('<sposet_builder' in text)
1366    assert('<determinantset>' in text)
1367    assert('<slaterdeterminant>' in text)
1368    assert('<determinant' in text)
1369    assert('<jastrow' in text)
1370    assert('<hamiltonian' in text)
1371    assert('<pairpot' in text)
1372    assert('<pseudo' in text)
1373    assert('<estimator' in text)
1374    assert('<qmc' in text)
1375    assert('<parameter' in text)
1376    assert('LR_dim_cutoff' in text)
1377    assert('"posArray"' in text)
1378    assert('elementType' in text)
1379    assert('type="spindensity"' in text)
1380
1381    qi_read.write(write_file)
1382
1383    qi_write = QmcpackInput(write_file)
1384    qi_write.pluralize()
1385
1386    # remove extraneous data members for purpose of comparison
1387    del qi_write._metadata.spo_u
1388    del qi_write._metadata.spo_d
1389    spob = qi_write.simulation.qmcsystem.wavefunctions.psi0.sposet_builders
1390    sposets = spob.bspline.sposets
1391    del sposets.spo_u.spos
1392    del sposets.spo_d.spos
1393
1394    check_vs_serial_reference(qi_write,ref_file)
1395
1396
1397    # test write for afqmc input file
1398    ref_file   = 'CH4_afqmc.in.xml'
1399    write_file = os.path.join(tpath,'write_'+ref_file)
1400
1401    qi_read = QmcpackInput(files[ref_file])
1402
1403    text = qi_read.write()
1404    assert('<simulation' in text)
1405    assert('<project' in text)
1406    assert('<random' in text)
1407    assert('<AFQMCInfo' in text)
1408    assert('<Hamiltonian' in text)
1409    assert('<Wavefunction' in text)
1410    assert('<WalkerSet' in text)
1411    assert('<Propagator' in text)
1412    assert('<execute' in text)
1413    assert('<Estimator' in text)
1414    assert('<OneRDM/>' in text)
1415    assert('<parameter' in text)
1416    assert('method="afqmc"' in text)
1417    assert('"NMO"' in text)
1418    assert('"NAEA"' in text)
1419    assert('"NAEB"' in text)
1420    assert('nWalkers' in text)
1421    assert('name="wfn0"' in text)
1422    assert('type="NOMSD"' in text)
1423    assert('afqmc.h5' in text)
1424    assert('yes' in text)
1425    assert('name="back_propagation"' in text)
1426
1427    qi_read.write(write_file)
1428
1429    qi_write = QmcpackInput(write_file)
1430    assert(qi_write.is_afqmc_input())
1431
1432    check_vs_serial_reference(qi_write,'CH4_afqmc.in.xml write')
1433#end def test_write
1434
1435
1436
1437def test_get():
1438    from qmcpack_input import QmcpackInput
1439
1440    files = get_files()
1441
1442    qi = QmcpackInput(files['VO2_M1_afm.in.xml'])
1443
1444    s    = qi.simulation
1445    p    = s.project
1446    qs   = s.qmcsystem
1447    sc   = qs.simulationcell
1448    pss  = qs.particlesets
1449    pse  = pss.e
1450    psi  = pss.ion0
1451    u    = pse.groups.u
1452    d    = pse.groups.d
1453    V    = psi.groups.V
1454    O    = psi.groups.O
1455    wf   = qs.wavefunction
1456    sb   = wf.sposet_builder
1457    spos = sb.sposets
1458    spou = spos.spo_u
1459    spod = spos.spo_d
1460    ds   = wf.determinantset
1461    sd   = ds.slaterdeterminant
1462    du   = sd.determinants.updet
1463    dd   = sd.determinants.downdet
1464    js   = wf.jastrows
1465    J1   = js.J1
1466    J2   = js.J2
1467    J3   = js.J3
1468    h   = qs.hamiltonian
1469    pps  = h.pairpots
1470    ee   = pps.ElecElec
1471    ii   = pps.IonIon
1472    ecp  = pps.PseudoPot
1473    ecps = ecp.pseudos
1474    mpc  = pps.MPC
1475    ests = h.estimators
1476    sdens= ests.SpinDensity
1477    kec  = ests.KEcorr
1478    vmc  = s.calculations[0]
1479    dmc1 = s.calculations[1]
1480    dmc2 = s.calculations[2]
1481
1482    search_map = dict(
1483        simulation        = s,
1484        project           = p,
1485        qmcsystem         = qs,
1486        simulationcell    = sc,
1487        particleset       = pss,
1488        e                 = pse,
1489        ion0              = psi,
1490        u                 = u,
1491        d                 = d,
1492        #V                 = V, # can find group or pseudo
1493        #O                 = O,
1494        wavefunction      = wf,
1495        sposet_builder    = sb,
1496        sposet            = spos,
1497        spo_u             = spou,
1498        spo_d             = spod,
1499        determinantset    = ds,
1500        slaterdeterminant = sd,
1501        updet             = du,
1502        downdet           = dd,
1503        jastrow           = js,
1504        J1                = J1,
1505        J2                = J2,
1506        J3                = J3,
1507        hamiltonian       = h,
1508        pairpot           = pps,
1509        ElecElec          = ee,
1510        IonIon            = ii,
1511        PseudoPot         = ecp,
1512        pseudo            = ecps,
1513        MPC               = mpc,
1514        estimator         = ests,
1515        SpinDensity       = sdens,
1516        KEcorr            = kec,
1517        series            = p.series,
1518        lattice           = sc.lattice,
1519        bconds            = sc.bconds,
1520        lr_dim_cutoff     = sc.lr_dim_cutoff,
1521        random            = pse.random,
1522        tilematrix        = sb.tilematrix,
1523        twistnum          = sb.twistnum,
1524        meshfactor        = sb.meshfactor,
1525        precision         = sb.precision,
1526        truncate          = sb.truncate,
1527        format            = ecp.format,
1528        ecut              = mpc.ecut,
1529        physical          = mpc.physical,
1530        grid              = sdens.grid,
1531        psi               = kec.psi,
1532        )
1533
1534    missing = 'a b c'.split()
1535
1536
1537    for k,vref in search_map.items():
1538        v = qi.get(k)
1539        assert(v is not None)
1540        assert(id(v)==id(vref))
1541    #end for
1542
1543    for k in missing:
1544        v = qi.get(k)
1545        assert(v is None)
1546    #end for
1547
1548
1549    qi.pluralize()
1550
1551    s    = qi.simulation
1552    p    = s.project
1553    qs   = s.qmcsystem
1554    sc   = qs.simulationcell
1555    pss  = qs.particlesets
1556    pse  = pss.e
1557    psi  = pss.ion0
1558    u    = pse.groups.u
1559    d    = pse.groups.d
1560    V    = psi.groups.V
1561    O    = psi.groups.O
1562    wfs  = qs.wavefunctions
1563    wf   = wfs.psi0
1564    sbs  = wf.sposet_builders
1565    sb   = sbs.bspline
1566    spos = sb.sposets
1567    spou = spos.spo_u
1568    spod = spos.spo_d
1569    ds   = wf.determinantset
1570    sd   = ds.slaterdeterminant
1571    du   = sd.determinants.updet
1572    dd   = sd.determinants.downdet
1573    js   = wf.jastrows
1574    J1   = js.J1
1575    J2   = js.J2
1576    J3   = js.J3
1577    hs   = qs.hamiltonians
1578    h    = hs.h0
1579    pps  = h.pairpots
1580    ee   = pps.ElecElec
1581    ii   = pps.IonIon
1582    ecp  = pps.PseudoPot
1583    ecps = ecp.pseudos
1584    mpc  = pps.MPC
1585    ests = h.estimators
1586    sdens= ests.SpinDensity
1587    kec  = ests.KEcorr
1588    vmc  = s.calculations[0]
1589    dmc1 = s.calculations[1]
1590    dmc2 = s.calculations[2]
1591
1592    search_map = dict(
1593        simulation        = s,
1594        project           = p,
1595        qmcsystem         = qs,
1596        simulationcell    = sc,
1597        particleset       = pss,
1598        e                 = pse,
1599        ion0              = psi,
1600        u                 = u,
1601        d                 = d,
1602        #V                 = V, # can find group or pseudo
1603        #O                 = O,
1604        wavefunction      = wfs,
1605        sposet_builder    = sbs,
1606        psi0              = wf,
1607        sposet            = spos,
1608        spo_u             = spou,
1609        spo_d             = spod,
1610        determinantset    = ds,
1611        slaterdeterminant = sd,
1612        updet             = du,
1613        downdet           = dd,
1614        jastrow           = js,
1615        J1                = J1,
1616        J2                = J2,
1617        J3                = J3,
1618        hamiltonian       = hs,
1619        h0                = h,
1620        pairpot           = pps,
1621        ElecElec          = ee,
1622        IonIon            = ii,
1623        PseudoPot         = ecp,
1624        pseudo            = ecps,
1625        MPC               = mpc,
1626        estimator         = ests,
1627        SpinDensity       = sdens,
1628        KEcorr            = kec,
1629        series            = p.series,
1630        lattice           = sc.lattice,
1631        bconds            = sc.bconds,
1632        lr_dim_cutoff     = sc.lr_dim_cutoff,
1633        random            = pse.random,
1634        tilematrix        = sb.tilematrix,
1635        twistnum          = sb.twistnum,
1636        meshfactor        = sb.meshfactor,
1637        precision         = sb.precision,
1638        truncate          = sb.truncate,
1639        format            = ecp.format,
1640        ecut              = mpc.ecut,
1641        physical          = mpc.physical,
1642        grid              = sdens.grid,
1643        psi               = kec.psi,
1644        )
1645
1646    for k,vref in search_map.items():
1647        v = qi.get(k)
1648        assert(v is not None)
1649        assert(id(v)==id(vref))
1650    #end for
1651
1652    for k in missing:
1653        v = qi.get(k)
1654        assert(v is None)
1655    #end for
1656
1657
1658    qi = QmcpackInput(files['CH4_afqmc.in.xml'])
1659
1660    s  = qi.simulation
1661    pr = s.project
1662    r  = s.random
1663    ai = s.afqmcinfo
1664    h  = s.hamiltonian
1665    wf = s.wavefunction
1666    ws = s.walkerset
1667    p  = s.propagator
1668    e  = s.execute
1669    bp = e.estimator
1670    dm = bp.onerdm
1671
1672    search_map = dict(
1673        simulation   = s,
1674        project      = pr,
1675        random       = r,
1676        afqmcinfo    = ai,
1677        hamiltonian  = h,
1678        wavefunction = wf,
1679        walkerset    = ws,
1680        propagator   = p,
1681        execute      = e,
1682        estimator    = bp,
1683        onerdm       = dm,
1684        id           = pr.id,
1685        series       = pr.series,
1686        seed         = r.seed,
1687        cutoff       = wf.cutoff,
1688        walker_type  = ws.walker_type,
1689        hybrid       = p.hybrid,
1690        blocks       = e.blocks,
1691        timestep     = e.timestep,
1692        steps        = e.steps,
1693        ncores       = e.ncores,
1694        nwalkers     = e.nwalkers,
1695        naverages    = bp.naverages,
1696        block_size   = bp.block_size,
1697        ortho        = bp.ortho,
1698        nsteps       = bp.nsteps,
1699        )
1700
1701    for k,vref in search_map.items():
1702        v = qi.get(k)
1703        assert(v is not None)
1704        assert(id(v)==id(vref))
1705    #end for
1706
1707    for k in missing:
1708        v = qi.get(k)
1709        assert(v is None)
1710    #end for
1711
1712#end def test_get
1713
1714
1715
1716def test_incorporate_system():
1717    from physical_system import generate_physical_system
1718    from qmcpack_input import generate_qmcpack_input
1719
1720    divert_nexus_log()
1721
1722    system = generate_physical_system(
1723        units    = 'A',
1724        axes     = '''
1725                    5.75200000    0.00000000    0.00000000
1726                    0.00000000    4.53780000    0.00000000
1727                   -2.90357335    0.00000000    4.53217035
1728                   ''',
1729        elem_pos = '''
1730                   V   1.30060289    4.44223393    0.11992123
1731                   V   1.54782377    0.09556607    4.41224912
1732                   V  -0.15118378    2.36446607    2.38600640
1733                   V   2.99961044    2.17333393    2.14616395
1734                   O   0.00517700    0.96155982    0.94541073
1735                   O   2.84324965    3.57624018    3.58675961
1736                   O  -1.44660967    1.30734018    3.21149591
1737                   O   4.29503633    3.23045982    1.32067444
1738                   O   1.43608828    3.18825828    1.35421250
1739                   O   1.41233837    1.34954172    3.17795785
1740                   O  -0.01569839    3.61844172    3.62029768
1741                   O   2.86412504    0.91935828    0.91187267
1742                   ''',
1743        V = 13,
1744        O = 6,
1745        )
1746
1747    qi = generate_qmcpack_input(
1748        input_type      = 'basic',
1749        system          = system,
1750        pseudos         = ['V.opt.xml','O.opt.xml'],
1751        spin_polarized  = True,
1752        twistnum        = 0,
1753        orbitals_h5     = 'scf.pwscf.h5',
1754        qmc = 'dmc',
1755        )
1756
1757    qi_ref = qi.copy()
1758
1759    shift = 0.1
1760    s = system.structure
1761    s.axes += shift
1762    s.pos  += shift
1763
1764    qi.incorporate_system(system)
1765
1766    axes_ref = qi_ref.get('lattice')
1767    psi_ref  = qi_ref.get('ion0')
1768
1769    axes     = qi.get('lattice')
1770    psi      = qi.get('ion0')
1771
1772    assert(value_eq(axes-shift,axes_ref))
1773    assert(value_eq(psi.groups.V.position-shift,psi_ref.groups.V.position))
1774    assert(value_eq(psi.groups.O.position-shift,psi_ref.groups.O.position))
1775
1776    del qi_ref.get('simulationcell').lattice
1777    del qi_ref.get('qmcsystem').particlesets
1778    del qi.get('simulationcell').lattice
1779    del qi.get('qmcsystem').particlesets
1780
1781    assert(object_eq(qi,qi_ref))
1782
1783    restore_nexus_log()
1784
1785#end def test_incorporate_system
1786
1787
1788
1789def test_generate_kspace_jastrow():
1790    from qmcpack_input import generate_kspace_jastrow
1791    kjas = generate_kspace_jastrow(1.0, 2.0, 2, 4)
1792    expect = '''<jastrow type="kSpace" name="Jk" source="ion0">
1793   <correlation kc="1.0" type="One-Body" symmetry="isotropic">
1794      <coefficients id="cG1" type="Array">
17950 0
1796      </coefficients>
1797   </correlation>
1798   <correlation kc="2.0" type="Two-Body" symmetry="isotropic">
1799      <coefficients id="cG2" type="Array">
18000 0 0 0
1801      </coefficients>
1802   </correlation>
1803</jastrow>
1804'''
1805    text = kjas.write()
1806    assert text == expect
1807#end def test_generate_kspace_jastrow
1808
1809
1810
1811def test_excited_state():
1812    from nexus import generate_physical_system
1813    from nexus import generate_qmcpack_input
1814
1815    dia = generate_physical_system(
1816        units     = 'A',
1817        axes      = [[ 1.785,  1.785,  0.   ],
1818                     [ 0.   ,  1.785,  1.785],
1819                     [ 1.785,  0.   ,  1.785]],
1820        elem      = ['C','C'],
1821        pos       = [[ 0.    ,  0.    ,  0.    ],
1822                     [ 0.8925,  0.8925,  0.8925]],
1823        tiling    = [3,1,3],
1824        kgrid     = (1,1,1),
1825        kshift    = (0,0,0),
1826        C         = 4
1827        )
1828
1829
1830    # test kp_index, band_index format (format="band")
1831    qmc_optical = generate_qmcpack_input(
1832        det_format     = 'old',
1833        spin_polarized = True,
1834        system         = dia,
1835        excitation     = ['up', '0 3 4 4'], #
1836        pseudos        = ['C.BFD.xml'],
1837        jastrows       = [],
1838        qmc            = 'vmc',
1839        )
1840
1841    expect = '''<slaterdeterminant>
1842   <determinant id="updet" size="36">
1843      <occupation mode="excited" spindataset="0" pairs="1" format="band">
18440 3 4 4
1845       </occupation>
1846   </determinant>
1847   <determinant id="downdet" size="36">
1848      <occupation mode="ground" spindataset="1"/>
1849   </determinant>
1850</slaterdeterminant>'''.strip()
1851
1852    text = qmc_optical.get('slaterdeterminant').write().strip()
1853    assert(text==expect)
1854
1855
1856    # test energy_index (format="energy")
1857    qmc_optical = generate_qmcpack_input(
1858        det_format     = 'old',
1859        spin_polarized = True,
1860        system         = dia,
1861        excitation     = ['up', '-35 36'], #
1862        pseudos        = ['C.BFD.xml'],
1863        jastrows       = [],
1864        qmc            = 'vmc',
1865        )
1866
1867    expect = '''<slaterdeterminant>
1868   <determinant id="updet" size="36">
1869      <occupation mode="excited" spindataset="0" pairs="1" format="energy">
1870-35 36
1871        </occupation>
1872   </determinant>
1873   <determinant id="downdet" size="36">
1874      <occupation mode="ground" spindataset="1"/>
1875   </determinant>
1876</slaterdeterminant>'''.strip()
1877
1878    text = qmc_optical.get('slaterdeterminant').write().strip()
1879    assert(text==expect)
1880
1881#end def test_excited_state
1882
1883
1884
1885if versions.seekpath_available:
1886    def test_symbolic_excited_state():
1887        from nexus import generate_physical_system
1888        from nexus import generate_qmcpack_input
1889
1890        dia = generate_physical_system(
1891            units     = 'A',
1892            axes      = [[ 1.785,  1.785,  0.   ],
1893                         [ 0.   ,  1.785,  1.785],
1894                         [ 1.785,  0.   ,  1.785]],
1895            elem      = ['C','C'],
1896            pos       = [[ 0.    ,  0.    ,  0.    ],
1897                         [ 0.8925,  0.8925,  0.8925]],
1898            use_prim  = True,    # Use SeeK-path library to identify prim cell
1899            tiling    = [2,1,2],
1900            kgrid     = (1,1,1),
1901            kshift    = (0,0,0), # Assumes we study transitions from Gamma. For non-gamma tilings, use kshift appropriately
1902            #C         = 4
1903            )
1904
1905        qmc_optical = generate_qmcpack_input(
1906            det_format     = 'old',
1907            input_type     = 'basic',
1908            spin_polarized = True,
1909            system         = dia,
1910            excitation     = ['up', 'gamma vb x cb'],
1911            jastrows       = [],
1912            qmc            = 'vmc',
1913            )
1914
1915        expect = '''<slaterdeterminant>
1916   <determinant id="updet" size="24">
1917      <occupation mode="excited" spindataset="0" pairs="1" format="band">
19180 5 3 6
1919       </occupation>
1920   </determinant>
1921   <determinant id="downdet" size="24">
1922      <occupation mode="ground" spindataset="1"/>
1923   </determinant>
1924</slaterdeterminant>'''.strip()
1925        text = qmc_optical.get('slaterdeterminant').write().strip()
1926        assert(text==expect)
1927
1928
1929        qmc_optical = generate_qmcpack_input(
1930            det_format     = 'old',
1931            input_type     = 'basic',
1932            spin_polarized = True,
1933            system         = dia,
1934            excitation     = ['up', 'gamma vb-1 x cb'],
1935            jastrows       = [],
1936            qmc            = 'vmc',
1937            )
1938
1939        expect = '''<slaterdeterminant>
1940   <determinant id="updet" size="24">
1941      <occupation mode="excited" spindataset="0" pairs="1" format="band">
19420 4 3 6
1943       </occupation>
1944   </determinant>
1945   <determinant id="downdet" size="24">
1946      <occupation mode="ground" spindataset="1"/>
1947   </determinant>
1948</slaterdeterminant>'''.strip()
1949        text = qmc_optical.get('slaterdeterminant').write().strip()
1950        assert(text==expect)
1951
1952
1953        qmc_optical = generate_qmcpack_input(
1954            det_format     = 'old',
1955            input_type     = 'basic',
1956            spin_polarized = True,
1957            system         = dia,
1958            excitation     = ['up', 'gamma vb x cb+1'],
1959            jastrows       = [],
1960            qmc            = 'vmc',
1961            )
1962
1963        expect = '''<slaterdeterminant>
1964   <determinant id="updet" size="24">
1965      <occupation mode="excited" spindataset="0" pairs="1" format="band">
19660 5 3 7
1967       </occupation>
1968   </determinant>
1969   <determinant id="downdet" size="24">
1970      <occupation mode="ground" spindataset="1"/>
1971   </determinant>
1972</slaterdeterminant>'''.strip()
1973        text = qmc_optical.get('slaterdeterminant').write().strip()
1974        assert(text==expect)
1975
1976    #end def test_symbolic_excited_state
1977#end if
1978
1979