~marcodalessandro76/bigdft/1.8

« back to all changes in this revision

Viewing changes to PyBigDFT/source/tutorials/Datasets.ipynb

  • Committer: marco.dalessandro at cnr
  • Date: 2018-12-04 10:14:11 UTC
  • Revision ID: marco.dalessandro@ism.cnr.it-20181204101411-g2xzyg5p4turzrpn
completed dataset tutorial and corrected minor errors in Fragments.py and Calculators.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
  },
44
44
  {
45
45
   "cell_type": "code",
46
 
   "execution_count": 2,
 
46
   "execution_count": 16,
47
47
   "metadata": {},
48
48
   "outputs": [
49
49
    {
68
68
  },
69
69
  {
70
70
   "cell_type": "code",
71
 
   "execution_count": 3,
 
71
   "execution_count": 17,
72
72
   "metadata": {},
73
73
   "outputs": [
74
74
    {
94
94
  },
95
95
  {
96
96
   "cell_type": "code",
97
 
   "execution_count": 4,
 
97
   "execution_count": 18,
98
98
   "metadata": {},
99
99
   "outputs": [
100
100
    {
112
112
  },
113
113
  {
114
114
   "cell_type": "code",
115
 
   "execution_count": 5,
 
115
   "execution_count": 19,
116
116
   "metadata": {},
117
 
   "outputs": [],
 
117
   "outputs": [
 
118
    {
 
119
     "data": {
 
120
      "text/plain": [
 
121
       "{'label': 'CO_GS',\n",
 
122
       " 'molecule_shape': 'linear',\n",
 
123
       " 'posinp': 'CO_posinp.xyz',\n",
 
124
       " 'run_dir': 'CO_GS'}"
 
125
      ]
 
126
     },
 
127
     "execution_count": 19,
 
128
     "metadata": {},
 
129
     "output_type": "execute_result"
 
130
    }
 
131
   ],
118
132
   "source": [
119
 
    "# how to remove a global options?\n",
120
 
    "# study.pop_global_option ??? "
 
133
    "# remove the new_option key\n",
 
134
    "study.pop_global_option('new_option')\n",
 
135
    "study.global_options()"
121
136
   ]
122
137
  },
123
138
  {
124
139
   "cell_type": "code",
125
 
   "execution_count": 6,
 
140
   "execution_count": 20,
126
141
   "metadata": {},
127
142
   "outputs": [
128
143
    {
131
146
       "{'dft': {'gnrm_cv': 1e-05, 'hgrids': 0.37}}"
132
147
      ]
133
148
     },
134
 
     "execution_count": 6,
 
149
     "execution_count": 20,
135
150
     "metadata": {},
136
151
     "output_type": "execute_result"
137
152
    }
153
168
  },
154
169
  {
155
170
   "cell_type": "code",
156
 
   "execution_count": 7,
 
171
   "execution_count": 21,
157
172
   "metadata": {},
158
173
   "outputs": [],
159
174
   "source": [
165
180
   "metadata": {},
166
181
   "source": [
167
182
    "We prepare the study for the convergence analysis by appending the run associated to the values of rmult. Each run\n",
168
 
    "is caractherized by an id and contain the InputFile object as input as well as the code used to perform the calculation"
 
183
    "is caractherized by an id and contain the InputFile object as input as well as the code used to perform the calculation. If the same id is provided more than one the function gives a Value Error"
169
184
   ]
170
185
  },
171
186
  {
172
187
   "cell_type": "code",
173
 
   "execution_count": 8,
 
188
   "execution_count": 22,
174
189
   "metadata": {},
175
190
   "outputs": [],
176
191
   "source": [
180
195
   ]
181
196
  },
182
197
  {
183
 
   "cell_type": "code",
184
 
   "execution_count": 9,
185
 
   "metadata": {},
186
 
   "outputs": [],
187
 
   "source": [
188
 
    "# TODO(?????) If the id is already provided do not add the new run and display a warning but do not give an error"
189
 
   ]
190
 
  },
191
 
  {
192
198
   "cell_type": "markdown",
193
199
   "metadata": {},
194
200
   "source": [
197
203
  },
198
204
  {
199
205
   "cell_type": "code",
200
 
   "execution_count": 10,
 
206
   "execution_count": 23,
201
207
   "metadata": {},
202
208
   "outputs": [
203
209
    {
204
210
     "name": "stdout",
205
211
     "output_type": "stream",
206
212
     "text": [
207
 
      "[{'runs': [0, 1, 2, 3], 'calc': <BigDFT.Calculators.SystemCalculator instance at 0x7f0e381afe18>}]\n",
 
213
      "[{'runs': [0, 1, 2, 3], 'calc': <BigDFT.Calculators.SystemCalculator instance at 0x7fda93752950>}]\n",
208
214
      "[{'rmult': 5.0}, {'rmult': 6.0}, {'rmult': 7.0}, {'rmult': 8.0}]\n"
209
215
     ]
210
216
    }
216
222
  },
217
223
  {
218
224
   "cell_type": "code",
219
 
   "execution_count": 11,
 
225
   "execution_count": 24,
220
226
   "metadata": {},
221
227
   "outputs": [
222
228
    {
224
230
     "output_type": "stream",
225
231
     "text": [
226
232
      "{'rmult': 7.0}\n",
227
 
      "{'molecule_shape': 'linear', 'run_dir': 'CO_GS', 'posinp': 'CO_posinp.xyz', 'input': {'dft': {'rmult': [7.0, 9.0], 'hgrids': 0.37, 'gnrm_cv': 1e-05}}, 'new_option': 'value', 'label': 'CO_GS'}\n"
 
233
      "{'molecule_shape': 'linear', 'run_dir': 'CO_GS', 'posinp': 'CO_posinp.xyz', 'input': {'dft': {'rmult': [7.0, 9.0], 'hgrids': 0.37, 'gnrm_cv': 1e-05}}, 'label': 'CO_GS'}\n"
228
234
     ]
229
235
    }
230
236
   ],
245
251
  },
246
252
  {
247
253
   "cell_type": "code",
248
 
   "execution_count": 12,
 
254
   "execution_count": 25,
249
255
   "metadata": {},
250
256
   "outputs": [
251
257
    {
254
260
       "['rmult:5.0', 'rmult:6.0', 'rmult:7.0', 'rmult:8.0']"
255
261
      ]
256
262
     },
257
 
     "execution_count": 12,
 
263
     "execution_count": 25,
258
264
     "metadata": {},
259
265
     "output_type": "execute_result"
260
266
    }
272
278
  },
273
279
  {
274
280
   "cell_type": "code",
275
 
   "execution_count": 13,
 
281
   "execution_count": 26,
276
282
   "metadata": {},
277
283
   "outputs": [
278
284
    {
296
302
      "Run directory CO_GS\n",
297
303
      "Executing command:  mpirun -np 4 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n rmult:8.0 -s Yes\n"
298
304
     ]
 
305
    },
 
306
    {
 
307
     "data": {
 
308
      "text/plain": [
 
309
       "{0: <BigDFT.Logfiles.Logfile instance at 0x7fdac7d69368>,\n",
 
310
       " 1: <BigDFT.Logfiles.Logfile instance at 0x7fda93752cb0>,\n",
 
311
       " 2: <BigDFT.Logfiles.Logfile instance at 0x7fda936bffc8>,\n",
 
312
       " 3: <BigDFT.Logfiles.Logfile instance at 0x7fdac41bfef0>}"
 
313
      ]
 
314
     },
 
315
     "execution_count": 26,
 
316
     "metadata": {},
 
317
     "output_type": "execute_result"
299
318
    }
300
319
   ],
301
320
   "source": [
302
 
    "# DIFFERENCE BETWEEN RUN AND PROCESS_RUN????\n",
303
 
    "results = study.run()"
304
 
   ]
305
 
  },
306
 
  {
307
 
   "cell_type": "code",
308
 
   "execution_count": 14,
309
 
   "metadata": {},
310
 
   "outputs": [],
311
 
   "source": [
312
 
    "# why does not use OMP_NUM_THREADS=2????????"
313
 
   ]
314
 
  },
315
 
  {
316
 
   "cell_type": "raw",
317
 
   "metadata": {},
318
 
   "source": [
319
 
    "Results is a dictionary that contains as key the cardinal value of the appended run and as value the instance of the log class of the associated computation"
320
 
   ]
321
 
  },
322
 
  {
323
 
   "cell_type": "code",
324
 
   "execution_count": 15,
 
321
    "study.run()"
 
322
   ]
 
323
  },
 
324
  {
 
325
   "cell_type": "markdown",
 
326
   "metadata": {},
 
327
   "source": [
 
328
    "The class member study.results contain a dictionary with the logfiles of the computations performed by the run method. The cardinal key respects the order of the append_run"
 
329
   ]
 
330
  },
 
331
  {
 
332
   "cell_type": "code",
 
333
   "execution_count": 30,
325
334
   "metadata": {},
326
335
   "outputs": [
327
336
    {
328
337
     "data": {
329
338
      "text/plain": [
330
 
       "{0: <BigDFT.Logfiles.Logfile instance at 0x7f0e3bd59830>,\n",
331
 
       " 1: <BigDFT.Logfiles.Logfile instance at 0x7f0e07725248>,\n",
332
 
       " 2: <BigDFT.Logfiles.Logfile instance at 0x7f0e07b68440>,\n",
333
 
       " 3: <BigDFT.Logfiles.Logfile instance at 0x7f0e381af908>}"
 
339
       "{0: <BigDFT.Logfiles.Logfile instance at 0x7fdac7d69368>,\n",
 
340
       " 1: <BigDFT.Logfiles.Logfile instance at 0x7fda93752cb0>,\n",
 
341
       " 2: <BigDFT.Logfiles.Logfile instance at 0x7fda936bffc8>,\n",
 
342
       " 3: <BigDFT.Logfiles.Logfile instance at 0x7fdac41bfef0>}"
334
343
      ]
335
344
     },
336
 
     "execution_count": 15,
 
345
     "execution_count": 30,
337
346
     "metadata": {},
338
347
     "output_type": "execute_result"
339
348
    }
340
349
   ],
341
350
   "source": [
 
351
    "results = study.results\n",
342
352
    "results"
343
353
   ]
344
354
  },
346
356
   "cell_type": "markdown",
347
357
   "metadata": {},
348
358
   "source": [
 
359
    "Several operation can be performed on the results by using the methods of the logfile class. Here we provide some examples"
 
360
   ]
 
361
  },
 
362
  {
 
363
   "cell_type": "markdown",
 
364
   "metadata": {},
 
365
   "source": [
349
366
    "Perform a convergence plot of the total energy w.r.t. the domain size"
350
367
   ]
351
368
  },
352
369
  {
353
370
   "cell_type": "code",
354
 
   "execution_count": 16,
 
371
   "execution_count": 32,
355
372
   "metadata": {},
356
373
   "outputs": [
357
374
    {
394
411
  },
395
412
  {
396
413
   "cell_type": "code",
397
 
   "execution_count": 17,
 
414
   "execution_count": 33,
398
415
   "metadata": {},
399
416
   "outputs": [
400
417
    {
417
434
  },
418
435
  {
419
436
   "cell_type": "code",
420
 
   "execution_count": 18,
 
437
   "execution_count": 34,
421
438
   "metadata": {},
422
439
   "outputs": [
423
440
    {
453
470
  },
454
471
  {
455
472
   "cell_type": "code",
456
 
   "execution_count": 21,
 
473
   "execution_count": 35,
457
474
   "metadata": {},
458
475
   "outputs": [
459
476
    {
460
477
     "data": {
461
478
      "text/plain": [
462
 
       "[<BigDFT.Logfiles.Logfile instance at 0x7f0e3bd59830>,\n",
463
 
       " <BigDFT.Logfiles.Logfile instance at 0x7f0e07725248>,\n",
464
 
       " <BigDFT.Logfiles.Logfile instance at 0x7f0e07b68440>,\n",
465
 
       " <BigDFT.Logfiles.Logfile instance at 0x7f0e381af908>]"
 
479
       "[<BigDFT.Logfiles.Logfile instance at 0x7fdac7d69368>,\n",
 
480
       " <BigDFT.Logfiles.Logfile instance at 0x7fda93752cb0>,\n",
 
481
       " <BigDFT.Logfiles.Logfile instance at 0x7fda936bffc8>,\n",
 
482
       " <BigDFT.Logfiles.Logfile instance at 0x7fdac41bfef0>]"
466
483
      ]
467
484
     },
468
 
     "execution_count": 21,
 
485
     "execution_count": 35,
469
486
     "metadata": {},
470
487
     "output_type": "execute_result"
471
488
    }
475
492
   ]
476
493
  },
477
494
  {
 
495
   "cell_type": "markdown",
 
496
   "metadata": {},
 
497
   "source": [
 
498
    "If an attribute and/or an id is provided fetch_results extracts only the wanted results, for instance"
 
499
   ]
 
500
  },
 
501
  {
478
502
   "cell_type": "code",
479
 
   "execution_count": 22,
 
503
   "execution_count": 36,
480
504
   "metadata": {},
481
505
   "outputs": [
482
506
    {
498
522
   "metadata": {},
499
523
   "source": [
500
524
    "It is also possible to define a post-processing function that is passed to the dataset instance. This function\n",
501
 
    "is called after the run and the output of study.run() contains the output of the post-processing function.\n",
 
525
    "is called after the run and the output of study.run() and contains the output of the post-processing function.\n",
502
526
    "We show some examples."
503
527
   ]
504
528
  },
511
535
  },
512
536
  {
513
537
   "cell_type": "code",
514
 
   "execution_count": 23,
 
538
   "execution_count": 37,
515
539
   "metadata": {},
516
540
   "outputs": [],
517
541
   "source": [
522
546
  },
523
547
  {
524
548
   "cell_type": "code",
525
 
   "execution_count": 24,
 
549
   "execution_count": 38,
526
550
   "metadata": {},
527
551
   "outputs": [],
528
552
   "source": [
531
555
  },
532
556
  {
533
557
   "cell_type": "code",
534
 
   "execution_count": 38,
 
558
   "execution_count": 39,
535
559
   "metadata": {},
536
560
   "outputs": [
537
561
    {
565
589
       " [-1.416639e-05, -1.416639e-05, -0.07195065]]"
566
590
      ]
567
591
     },
568
 
     "execution_count": 38,
 
592
     "execution_count": 39,
569
593
     "metadata": {},
570
594
     "output_type": "execute_result"
571
595
    }
584
608
  },
585
609
  {
586
610
   "cell_type": "code",
587
 
   "execution_count": 39,
 
611
   "execution_count": 40,
588
612
   "metadata": {},
589
613
   "outputs": [],
590
614
   "source": [
598
622
  },
599
623
  {
600
624
   "cell_type": "code",
601
 
   "execution_count": 40,
 
625
   "execution_count": 41,
602
626
   "metadata": {},
603
627
   "outputs": [],
604
628
   "source": [
607
631
  },
608
632
  {
609
633
   "cell_type": "code",
610
 
   "execution_count": 41,
 
634
   "execution_count": 42,
611
635
   "metadata": {},
612
636
   "outputs": [
613
637
    {
641
665
       " [25.16, 25.16, 25.16]]"
642
666
      ]
643
667
     },
644
 
     "execution_count": 41,
 
668
     "execution_count": 42,
645
669
     "metadata": {},
646
670
     "output_type": "execute_result"
647
671
    }
667
691
  },
668
692
  {
669
693
   "cell_type": "code",
670
 
   "execution_count": 44,
 
694
   "execution_count": 43,
671
695
   "metadata": {},
672
696
   "outputs": [
673
697
    {
685
709
  },
686
710
  {
687
711
   "cell_type": "code",
688
 
   "execution_count": 57,
 
712
   "execution_count": 44,
689
713
   "metadata": {},
690
714
   "outputs": [
691
715
    {
705
729
  },
706
730
  {
707
731
   "cell_type": "code",
708
 
   "execution_count": 48,
 
732
   "execution_count": 45,
709
733
   "metadata": {},
710
734
   "outputs": [
711
735
    {
714
738
       "{'dft': {'gnrm_cv': 1e-05, 'hgrids': 0.37, 'rmult': [7.0, 9.0]}}"
715
739
      ]
716
740
     },
717
 
     "execution_count": 48,
 
741
     "execution_count": 45,
718
742
     "metadata": {},
719
743
     "output_type": "execute_result"
720
744
    }
734
758
  },
735
759
  {
736
760
   "cell_type": "code",
737
 
   "execution_count": 77,
 
761
   "execution_count": 46,
738
762
   "metadata": {},
739
763
   "outputs": [],
740
764
   "source": [
749
773
  },
750
774
  {
751
775
   "cell_type": "code",
752
 
   "execution_count": 78,
 
776
   "execution_count": 47,
753
777
   "metadata": {},
754
778
   "outputs": [
755
779
    {
766
790
  },
767
791
  {
768
792
   "cell_type": "code",
769
 
   "execution_count": 91,
 
793
   "execution_count": 48,
770
794
   "metadata": {},
771
795
   "outputs": [],
772
796
   "source": [
773
797
    "def extract_alpha(ef):\n",
774
798
    "    \"\"\"\n",
775
 
    "    \\alpha_ij isthe i-th component of the vector d-d0, computed with a field in the j-th direction,\n",
 
799
    "    alpha_ij isthe i-th component of the vector d-d0, computed with a field in the j-th direction,\n",
776
800
    "    divided for the intensity of the field.\n",
777
801
    "    \"\"\"\n",
778
802
    "    d0=np.array(ef.get_global_option('d0'))\n",
786
810
  },
787
811
  {
788
812
   "cell_type": "code",
789
 
   "execution_count": 92,
 
813
   "execution_count": 49,
790
814
   "metadata": {},
791
815
   "outputs": [],
792
816
   "source": [
795
819
  },
796
820
  {
797
821
   "cell_type": "code",
798
 
   "execution_count": 93,
 
822
   "execution_count": 50,
799
823
   "metadata": {},
800
824
   "outputs": [
801
825
    {
824
848
       "        [-1.32899430e-04, -1.32899430e-04,  1.87275470e+01]])"
825
849
      ]
826
850
     },
827
 
     "execution_count": 93,
 
851
     "execution_count": 50,
828
852
     "metadata": {},
829
853
     "output_type": "execute_result"
830
854
    }
835
859
   ]
836
860
  },
837
861
  {
838
 
   "cell_type": "code",
839
 
   "execution_count": null,
840
 
   "metadata": {},
841
 
   "outputs": [],
842
 
   "source": []
843
 
  },
844
 
  {
845
 
   "cell_type": "code",
846
 
   "execution_count": null,
847
 
   "metadata": {},
848
 
   "outputs": [],
849
 
   "source": []
850
 
  },
851
 
  {
852
 
   "cell_type": "code",
853
 
   "execution_count": null,
854
 
   "metadata": {},
855
 
   "outputs": [],
856
 
   "source": []
857
 
  },
858
 
  {
859
 
   "cell_type": "code",
860
 
   "execution_count": null,
861
 
   "metadata": {},
862
 
   "outputs": [],
863
 
   "source": []
864
 
  },
865
 
  {
866
 
   "cell_type": "code",
867
 
   "execution_count": null,
868
 
   "metadata": {},
869
 
   "outputs": [],
870
 
   "source": []
871
 
  },
872
 
  {
873
 
   "cell_type": "code",
874
 
   "execution_count": null,
875
 
   "metadata": {},
876
 
   "outputs": [],
877
 
   "source": []
878
 
  },
879
 
  {
880
 
   "cell_type": "code",
881
 
   "execution_count": null,
882
 
   "metadata": {},
883
 
   "outputs": [],
 
862
   "cell_type": "markdown",
 
863
   "metadata": {},
884
864
   "source": [
885
 
    "###############################################################################################"
 
865
    "A list of posinp for several molecules can be found as follows"
886
866
   ]
887
867
  },
888
868
  {
889
869
   "cell_type": "code",
890
 
   "execution_count": 2,
 
870
   "execution_count": 6,
891
871
   "metadata": {},
892
872
   "outputs": [
893
873
    {
894
874
     "name": "stdout",
895
875
     "output_type": "stream",
896
876
     "text": [
897
 
      "{'units': 'angstroem', 'positions': [{'C': [0.0, 0.0, 0.0], 'sym': 'C'}, {'sym': 'O', 'O': [0.0, 0.0, 1.1282]}], 'global monopole': 0.0}\n"
 
877
      "Warning, line not parsed: \" C 0.0000 0.0000 0.0000\n",
 
878
      " 'NoneType' object has no attribute '__getitem__' \"\n",
 
879
      "Warning, line not parsed: \" O 0.0000 0.0000 1.1282 'NoneType' object has no attribute '__getitem__' \"\n",
 
880
      "{'units': 'angstroem', 'positions': [], 'global monopole': 0.0}\n"
898
881
     ]
899
882
    }
900
883
   ],
905
888
   ]
906
889
  },
907
890
  {
908
 
   "cell_type": "code",
909
 
   "execution_count": 3,
910
 
   "metadata": {
911
 
    "scrolled": true
912
 
   },
913
 
   "outputs": [],
914
 
   "source": [
915
 
    "inp=I.Inputfile({'dft': {'rmult': [3,8]}})"
916
 
   ]
917
 
  },
918
 
  {
919
 
   "cell_type": "code",
920
 
   "execution_count": 4,
921
 
   "metadata": {
922
 
    "scrolled": true
923
 
   },
924
 
   "outputs": [
925
 
    {
926
 
     "name": "stdout",
927
 
     "output_type": "stream",
928
 
     "text": [
929
 
      "Initialize a Calculator with OMP_NUM_THREADS=2 and command mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft\n"
930
 
     ]
931
 
    }
932
 
   ],
933
 
   "source": [
934
 
    "code=C.SystemCalculator(omp=2,mpi_run='mpirun -np 2')"
935
 
   ]
936
 
  },
937
 
  {
938
 
   "cell_type": "code",
939
 
   "execution_count": 5,
940
 
   "metadata": {},
941
 
   "outputs": [
942
 
    {
943
 
     "data": {
944
 
      "text/plain": [
945
 
       "<module 'BigDFT.Datasets' from '/home/marco/Applications/BigDFT/binaries/v1.8.3/install/lib/python2.7/site-packages/BigDFT/Datasets.pyc'>"
946
 
      ]
947
 
     },
948
 
     "execution_count": 5,
949
 
     "metadata": {},
950
 
     "output_type": "execute_result"
951
 
    }
952
 
   ],
953
 
   "source": [
954
 
    "reload(D)"
955
 
   ]
956
 
  },
957
 
  {
958
 
   "cell_type": "code",
959
 
   "execution_count": 6,
960
 
   "metadata": {},
961
 
   "outputs": [],
962
 
   "source": [
963
 
    "study=D.Dataset(label='CO',run_dir='CO',posinp=CO)"
964
 
   ]
965
 
  },
966
 
  {
967
 
   "cell_type": "code",
968
 
   "execution_count": 7,
969
 
   "metadata": {},
970
 
   "outputs": [],
971
 
   "source": [
972
 
    "inp.set_rmult(coarse=3)\n",
973
 
    "study.append_run(id={'crmult': 3}, runner= code, input=inp,skip=False)\n",
974
 
    "inp.set_rmult(coarse=4)\n",
975
 
    "study.append_run(id={'crmult': 4}, runner= code, input=inp)\n",
976
 
    "inp.set_rmult(coarse=5)\n",
977
 
    "study.append_run(id={'crmult': 5}, runner= code, input=inp)"
978
 
   ]
979
 
  },
980
 
  {
981
 
   "cell_type": "code",
982
 
   "execution_count": 8,
983
 
   "metadata": {},
984
 
   "outputs": [],
985
 
   "source": [
986
 
    "code.update_global_options(skip=False)"
987
 
   ]
988
 
  },
989
 
  {
990
 
   "cell_type": "code",
991
 
   "execution_count": 9,
992
 
   "metadata": {},
993
 
   "outputs": [
994
 
    {
995
 
     "name": "stdout",
996
 
     "output_type": "stream",
997
 
     "text": [
998
 
      "Creating the yaml input file \"CO/crmult:3.yaml\"\n",
999
 
      "Run directory CO\n",
1000
 
      "Executing command:  mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n crmult:3\n",
1001
 
      "Creating the yaml input file \"CO/crmult:4.yaml\"\n",
1002
 
      "Run directory CO\n",
1003
 
      "Executing command:  mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n crmult:4\n",
1004
 
      "Creating the yaml input file \"CO/crmult:5.yaml\"\n",
1005
 
      "Run directory CO\n",
1006
 
      "Executing command:  mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n crmult:5\n"
1007
 
     ]
1008
 
    }
1009
 
   ],
1010
 
   "source": [
1011
 
    "data=study.run()"
1012
 
   ]
1013
 
  },
1014
 
  {
1015
 
   "cell_type": "code",
1016
 
   "execution_count": 10,
1017
 
   "metadata": {},
1018
 
   "outputs": [
1019
 
    {
1020
 
     "data": {
1021
 
      "text/plain": [
1022
 
       "[-21.611635946132814, -21.64835568408899, -21.651311269276533]"
1023
 
      ]
1024
 
     },
1025
 
     "execution_count": 10,
1026
 
     "metadata": {},
1027
 
     "output_type": "execute_result"
1028
 
    }
1029
 
   ],
1030
 
   "source": [
1031
 
    "study.fetch_results(attribute='energy')"
1032
 
   ]
1033
 
  },
1034
 
  {
1035
 
   "cell_type": "code",
1036
 
   "execution_count": 11,
1037
 
   "metadata": {},
1038
 
   "outputs": [
1039
 
    {
1040
 
     "name": "stdout",
1041
 
     "output_type": "stream",
1042
 
     "text": [
1043
 
      "{'run_dir': 'CO', 'input': {'dft': {'rmult': [3, 8.0]}}, 'posinp': {'units': 'angstroem', 'positions': [{'C': [0.0, 0.0, 0.0], 'sym': 'C'}, {'O': [0.0, 0.0, 1.1282], 'sym': 'O'}], 'global monopole': 0.0}, 'skip': False, 'label': 'CO'}\n",
1044
 
      "-21.6116359461\n",
1045
 
      "{'run_dir': 'CO', 'input': {'dft': {'rmult': [4, 8.0]}}, 'posinp': {'units': 'angstroem', 'positions': [{'C': [0.0, 0.0, 0.0], 'sym': 'C'}, {'O': [0.0, 0.0, 1.1282], 'sym': 'O'}], 'global monopole': 0.0}, 'label': 'CO'}\n",
1046
 
      "-21.6483556841\n",
1047
 
      "{'run_dir': 'CO', 'input': {'dft': {'rmult': [5, 8.0]}}, 'posinp': {'units': 'angstroem', 'positions': [{'C': [0.0, 0.0, 0.0], 'sym': 'C'}, {'O': [0.0, 0.0, 1.1282], 'sym': 'O'}], 'global monopole': 0.0}, 'label': 'CO'}\n",
1048
 
      "-21.6513112693\n"
1049
 
     ]
1050
 
    }
1051
 
   ],
1052
 
   "source": [
1053
 
    "for d in range(len(study.runs)):\n",
1054
 
    "    print study.runs[d]\n",
1055
 
    "    print study.results[d].energy"
1056
 
   ]
1057
 
  },
1058
 
  {
1059
891
   "cell_type": "markdown",
1060
892
   "metadata": {},
1061
893
   "source": [
1062
 
    "# Polarizability tensor of a molecule"
1063
 
   ]
1064
 
  },
1065
 
  {
1066
 
   "cell_type": "code",
1067
 
   "execution_count": 87,
1068
 
   "metadata": {},
1069
 
   "outputs": [
1070
 
    {
1071
 
     "name": "stdout",
1072
 
     "output_type": "stream",
1073
 
     "text": [
1074
 
      "Creating the yaml input file \"./CO-GS.yaml\"\n",
1075
 
      "Executing command:  mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n CO-GS\n"
1076
 
     ]
1077
 
    }
1078
 
   ],
1079
 
   "source": [
1080
 
    "inp=I.Inputfile()\n",
1081
 
    "mol=Molecules.Molecule('CO')\n",
1082
 
    "#mol['positions'][1]['O']=[0.0,0.0,1.12016] #our positions\n",
1083
 
    "inp.set_xc('PBE')\n",
1084
 
    "inp.set_hgrid('0.37')\n",
1085
 
    "inp.set_rmult(coarse=11)\n",
1086
 
    "logGS=code.run(input=inp,posinp=mol,name='CO-GS')"
1087
 
   ]
1088
 
  },
1089
 
  {
1090
 
   "cell_type": "code",
1091
 
   "execution_count": 88,
1092
 
   "metadata": {},
1093
 
   "outputs": [],
1094
 
   "source": [
1095
 
    "import numpy as np\n",
1096
 
    "intensity=-1.e-2\n",
1097
 
    "PolTensor=D.Dataset(label='Poltensor',run_dir='polt',input=inp,posinp=mol,d0=logGS.dipole,F=intensity)\n",
1098
 
    "for idir,coord in enumerate(['x','y','z']):\n",
1099
 
    "    el=np.zeros(3)\n",
1100
 
    "    el[idir]=intensity\n",
1101
 
    "    inp.apply_electric_field(el.tolist())\n",
1102
 
    "    PolTensor.append_run({'id': coord,'F':intensity},code,input=inp)"
1103
 
   ]
1104
 
  },
1105
 
  {
1106
 
   "cell_type": "code",
1107
 
   "execution_count": 89,
1108
 
   "metadata": {},
1109
 
   "outputs": [],
1110
 
   "source": [
1111
 
    "def extract_alpha(PolT):\n",
1112
 
    "    d0=np.array(PolT.get_global_option('d0'))\n",
1113
 
    "    F=PolT.get_global_option('F')\n",
1114
 
    "    ds=PolT.fetch_results(attribute='dipole')\n",
1115
 
    "    alpha=np.mat(np.zeros(9)).reshape(3,3)\n",
1116
 
    "    for idir in range(3):\n",
1117
 
    "        alpha[idir]=(np.array(ds[idir])-d0)/F\n",
1118
 
    "    return alpha"
1119
 
   ]
1120
 
  },
1121
 
  {
1122
 
   "cell_type": "code",
1123
 
   "execution_count": 90,
1124
 
   "metadata": {},
1125
 
   "outputs": [],
1126
 
   "source": [
1127
 
    "code.update_global_options(skip=False)"
1128
 
   ]
1129
 
  },
1130
 
  {
1131
 
   "cell_type": "code",
1132
 
   "execution_count": 91,
1133
 
   "metadata": {},
1134
 
   "outputs": [],
1135
 
   "source": [
1136
 
    "PolTensor.set_postprocessing_function(extract_alpha)"
1137
 
   ]
1138
 
  },
1139
 
  {
1140
 
   "cell_type": "code",
1141
 
   "execution_count": 92,
1142
 
   "metadata": {},
1143
 
   "outputs": [
1144
 
    {
1145
 
     "name": "stdout",
1146
 
     "output_type": "stream",
1147
 
     "text": [
1148
 
      "Creating the yaml input file \"polt/F:-0.01,id:x.yaml\"\n",
1149
 
      "Run directory polt\n",
1150
 
      "Executing command:  mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n F:-0.01,id:x\n",
1151
 
      "Creating the yaml input file \"polt/F:-0.01,id:y.yaml\"\n",
1152
 
      "Run directory polt\n",
1153
 
      "Executing command:  mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n F:-0.01,id:y\n",
1154
 
      "Creating the yaml input file \"polt/F:-0.01,id:z.yaml\"\n",
1155
 
      "Run directory polt\n",
1156
 
      "Executing command:  mpirun -np 2 /home/marco/Applications/BigDFT/binaries/v1.8.3/install/bin/bigdft -n F:-0.01,id:z\n"
1157
 
     ]
1158
 
    }
1159
 
   ],
1160
 
   "source": [
1161
 
    "alpha=PolTensor.run()"
1162
 
   ]
1163
 
  },
1164
 
  {
1165
 
   "cell_type": "code",
1166
 
   "execution_count": 50,
1167
 
   "metadata": {},
1168
 
   "outputs": [],
1169
 
   "source": [
1170
 
    "alpha1=_"
1171
 
   ]
1172
 
  },
1173
 
  {
1174
 
   "cell_type": "code",
1175
 
   "execution_count": 51,
1176
 
   "metadata": {},
1177
 
   "outputs": [
1178
 
    {
1179
 
     "data": {
1180
 
      "text/plain": [
1181
 
       "matrix([[ 1.26423306e+01,  3.50890610e-03, -3.31700000e-02],\n",
1182
 
       "        [ 3.50890610e-03,  1.26423306e+01, -3.31700000e-02],\n",
1183
 
       "        [ 3.70690000e-05,  3.70690000e-05,  1.58543700e+01]])"
1184
 
      ]
1185
 
     },
1186
 
     "execution_count": 51,
1187
 
     "metadata": {},
1188
 
     "output_type": "execute_result"
1189
 
    }
1190
 
   ],
1191
 
   "source": [
1192
 
    "alpha1"
1193
 
   ]
1194
 
  },
1195
 
  {
1196
 
   "cell_type": "code",
1197
 
   "execution_count": 64,
1198
 
   "metadata": {},
1199
 
   "outputs": [],
1200
 
   "source": [
1201
 
    "alpha2=alpha"
1202
 
   ]
1203
 
  },
1204
 
  {
1205
 
   "cell_type": "code",
1206
 
   "execution_count": 65,
1207
 
   "metadata": {},
1208
 
   "outputs": [
1209
 
    {
1210
 
     "data": {
1211
 
      "text/plain": [
1212
 
       "matrix([[ 1.26423306e+01,  3.50890610e-03, -3.31700000e-02],\n",
1213
 
       "        [ 3.50890610e-03,  1.26423306e+01, -3.31700000e-02],\n",
1214
 
       "        [ 3.70690000e-05,  3.70690000e-05,  1.58543700e+01]])"
1215
 
      ]
1216
 
     },
1217
 
     "execution_count": 65,
1218
 
     "metadata": {},
1219
 
     "output_type": "execute_result"
1220
 
    }
1221
 
   ],
1222
 
   "source": [
1223
 
    "alpha1"
1224
 
   ]
1225
 
  },
1226
 
  {
1227
 
   "cell_type": "code",
1228
 
   "execution_count": 57,
1229
 
   "metadata": {},
1230
 
   "outputs": [
1231
 
    {
1232
 
     "data": {
1233
 
      "text/plain": [
1234
 
       "{0: <BigDFT.Logfiles.Logfile instance at 0x7f02c026f950>,\n",
1235
 
       " 1: <BigDFT.Logfiles.Logfile instance at 0x7f02c026f7a0>,\n",
1236
 
       " 2: <BigDFT.Logfiles.Logfile instance at 0x7f0291a53128>}"
1237
 
      ]
1238
 
     },
1239
 
     "execution_count": 57,
1240
 
     "metadata": {},
1241
 
     "output_type": "execute_result"
1242
 
    }
1243
 
   ],
1244
 
   "source": [
1245
 
    "alpha2"
1246
 
   ]
1247
 
  },
1248
 
  {
1249
 
   "cell_type": "code",
1250
 
   "execution_count": 85,
1251
 
   "metadata": {},
1252
 
   "outputs": [
1253
 
    {
1254
 
     "data": {
1255
 
      "text/plain": [
1256
 
       "matrix([[ 1.26686738e+01, -3.23449840e-03,  3.77370000e-02],\n",
1257
 
       "        [-3.23449840e-03,  1.26686738e+01,  3.77370000e-02],\n",
1258
 
       "        [-1.11158900e-03, -1.11158900e-03,  1.58224360e+01]])"
1259
 
      ]
1260
 
     },
1261
 
     "execution_count": 85,
1262
 
     "metadata": {},
1263
 
     "output_type": "execute_result"
1264
 
    }
1265
 
   ],
1266
 
   "source": [
1267
 
    "alpha"
1268
 
   ]
1269
 
  },
1270
 
  {
1271
 
   "cell_type": "code",
1272
 
   "execution_count": 68,
1273
 
   "metadata": {},
1274
 
   "outputs": [],
1275
 
   "source": [
1276
 
    "a=0.5*(alpha1+alpha2)"
1277
 
   ]
1278
 
  },
1279
 
  {
1280
 
   "cell_type": "code",
1281
 
   "execution_count": 93,
1282
 
   "metadata": {},
1283
 
   "outputs": [
1284
 
    {
1285
 
     "data": {
1286
 
      "text/plain": [
1287
 
       "2.1334035481704943"
1288
 
      ]
1289
 
     },
1290
 
     "execution_count": 93,
1291
 
     "metadata": {},
1292
 
     "output_type": "execute_result"
1293
 
    }
1294
 
   ],
1295
 
   "source": [
1296
 
    "np.mean(np.diag(alpha))*(0.529177**3)"
 
894
    "so this analysis can be easily performed for other cases."
1297
895
   ]
1298
896
  },
1299
897
  {