├── Benchmarks ├── DFTB │ ├── README.md │ ├── dftb_in.hsd │ └── geo_end.gen ├── README.md ├── VASP-Quick │ ├── INCAR │ ├── KPOINTS │ ├── POSCAR │ └── POTCAR └── VASP-performance │ ├── INCAR │ ├── POSCAR │ ├── POTCAR │ └── README.md ├── Exploring └── Descriptors │ ├── README.md │ ├── data.final-cunb │ └── in.snap ├── External └── XRD_idea.ipynb ├── Phys771 └── README.md ├── README.md ├── Scripts ├── ASE │ ├── Demo.ipynb │ ├── Model_construction.ipynb │ ├── gra.vasp │ └── supercell.py ├── Aflow │ └── demo.ipynb ├── CSD │ └── CSD_error.ipynb ├── Pymatgen │ ├── ELF.py │ ├── Element.py │ ├── POSCAR2cif.py │ ├── auto-calc.py │ ├── bcc-sub.py │ ├── check_Stability.py │ ├── cif2POSCAR.py │ ├── download_json.py │ ├── search.py │ ├── search_dimer.ipynb │ └── work │ │ ├── Gap_screen-1.csv │ │ ├── Gap_screen-2.csv │ │ ├── Gap_screen-3.csv │ │ ├── Gap_screen-4.csv │ │ └── gap_screen.py ├── README.md └── USPEX │ ├── Extract_USPEX.py │ ├── POSCAR │ ├── README.md │ └── USPEX.mat ├── Tutorials ├── Convex_hull │ ├── 1.txt │ ├── Convex_hull.ipynb │ ├── Cr-B.txt │ ├── Cr-B0.txt │ ├── Pareto.ipynb │ └── convex_hull.py ├── HPC │ └── cori.pdf ├── MD_Lammps_lecture │ └── MD_Lammps.pdf ├── ML │ ├── Intro-NN.ipynb │ ├── MLP model from scikit-learn.ipynb │ ├── MLP model from the scratch.ipynb │ ├── Readme.md │ └── img │ │ ├── MLP.jpeg │ │ ├── neuron.png │ │ └── nn.png ├── README.md └── VASP_lecture │ ├── readme.md │ └── vasp.pdf ├── img ├── 1.png ├── 2.png ├── convex_hull_1.png ├── convex_hull_2.png ├── convex_hull_3.png ├── convex_hull_4.png ├── convex_hull_5.png ├── convex_hull_6.png ├── convex_hull_7.png ├── convex_hull_8.png └── convex_hull_9.png └── misc ├── LR_order.py ├── Order_plot.py ├── PES.txt ├── amorphous.ipynb ├── run.py ├── stereograph.txt ├── test.html └── test.png /Benchmarks/DFTB/README.md: -------------------------------------------------------------------------------- 1 | # DFTB+ 2 | 3 | This is an exmple of geometry optimization of a molecuar crystal with DFTB+. 4 | 5 | Although DFTB+ calculation can be automated throught ASE, there exist a bug when choosing the `MaxAngularMomentum`. For the given input, ASE generates: 6 | 7 | ``` 8 | MaxAngularMomentum = { 9 | C = "p" 10 | H = "s" 11 | O = "p" 12 | S = "p" 13 | } 14 | ``` 15 | But the MaxAngularMomentun for S is `d`, not `p`. Otherwise, the geometry will become wrong! 16 | 17 | The relevant dicussion can be found at: 18 | https://gitlab.com/ase/ase/-/issues/542 19 | -------------------------------------------------------------------------------- /Benchmarks/DFTB/dftb_in.hsd: -------------------------------------------------------------------------------- 1 | Geometry = GenFormat { 2 | <<< "geo_end.gen" 3 | } 4 | 5 | Driver = ConjugateGradient{ 6 | MaxForceComponent = 1E-4 7 | MaxSteps = 500 8 | } 9 | Hamiltonian = DFTB{ 10 | Dispersion = DftD3{ 11 | Damping = BeckeJohnson{ 12 | a1 = 0.746 13 | a2 = 4.191 14 | } 15 | s6 = 1.0 16 | s8 = 3.209 17 | } 18 | KPointsAndWeights = SupercellFolding { 19 | 2 0 0 20 | 0 3 0 21 | 0 0 2 22 | 0.5 0.0 0.5 23 | } 24 | MaxAngularMomentum = { 25 | C = "p" 26 | H = "s" 27 | O = "p" 28 | S = "d" #"p" 29 | } 30 | MaxSCCIterations = 1000 31 | Mixer = DIIS{} 32 | SCC = yes 33 | SCCTolerance = 1e-05 34 | SlaterKosterFiles = Type2FileNames{ 35 | Prefix = /scratch/qzhu/lib/Dftb+sk/mio-1-1/ 36 | Separator = "-" 37 | Suffix = ".skf" 38 | } 39 | } 40 | Options { 41 | WriteResultsTag = Yes 42 | } 43 | runmanyDftbsteps = True 44 | ParserOptions { 45 | IgnoreUnprocessedNodes = Yes 46 | } 47 | -------------------------------------------------------------------------------- /Benchmarks/DFTB/geo_end.gen: -------------------------------------------------------------------------------- 1 | 2 | H C O S 3 | 1 1 0.3184761639E+01 -0.5915205078E-01 0.1289360120E+02 4 | 2 1 0.1840093988E+01 0.2658928901E+01 0.6722983492E+01 5 | 3 1 0.1303421625E+01 0.4604819831E+00 0.1151410103E+02 6 | 4 1 0.1029071599E+01 0.2175116755E+01 0.1103859957E+02 7 | 5 1 0.3170942790E+01 0.3609926978E+01 0.1055719938E+02 8 | 6 1 0.5418204015E+01 0.4192603523E+01 0.1149998027E+02 9 | 7 1 0.6533043570E+01 0.2660619487E+01 0.1313648732E+02 10 | 8 1 0.5402672154E+01 0.5614729769E+00 0.1385419154E+02 11 | 9 1 0.5480100689E+01 0.3322822975E+01 -0.4386385411E+01 12 | 10 1 0.1485285111E+02 0.2721652657E+01 0.1135410444E+01 13 | 11 1 0.4662215834E+00 0.3716773401E+01 0.6331465627E+01 14 | 12 1 0.1611044924E+02 0.4272098134E+01 0.2646867982E+01 15 | 13 1 0.1252200043E+02 0.6560227458E+01 0.3404590371E+01 16 | 14 1 0.9583275581E+01 0.6607819256E+01 0.1529442472E+01 17 | 15 1 0.1041655126E+02 0.6478123402E+01 0.3136340505E+01 18 | 16 1 0.9042678859E+01 0.5420278901E+01 0.2744822641E+01 19 | 17 1 0.9579351222E+01 0.3221831983E+01 -0.2046294894E+01 20 | 18 1 0.9853701248E+01 0.4936466755E+01 -0.1570793440E+01 21 | 19 1 0.7711830060E+01 0.6371276981E+01 -0.1089393243E+01 22 | 20 1 0.5464568830E+01 0.6953953523E+01 -0.2032174139E+01 23 | 21 1 0.4349729282E+01 0.5421969486E+01 -0.3668681184E+01 24 | 22 1 0.1495557074E+02 0.6172619123E+01 0.3755218401E+01 25 | 23 1 0.1299497266E+01 0.3846469255E+01 0.7938363660E+01 26 | 24 1 0.7698011209E+01 0.2702197949E+01 -0.3425795064E+01 27 | 25 1 -0.4072797898E+01 0.3411269123E+01 0.5712587732E+01 28 | 26 1 -0.3970078263E+01 -0.3969734361E-01 0.8332395688E+01 29 | 27 1 -0.1639227582E+01 0.3798877458E+01 0.6063215761E+01 30 | 28 1 -0.5227676394E+01 0.1510748134E+01 0.6820938150E+01 31 | 29 2 -0.3457142146E+01 0.7947619705E+00 0.7833968688E+01 32 | 30 2 0.7826482364E+01 0.4487230793E+01 -0.2189315782E+01 33 | 31 2 0.7206546271E+01 0.5691723404E+01 -0.1812885050E+01 34 | 32 2 0.5960650035E+01 0.6025237040E+01 -0.2346085763E+01 35 | 33 2 0.5339169719E+01 0.5170425856E+01 -0.3263646204E+01 36 | 34 2 0.5967218843E+01 0.3988463450E+01 -0.3660147653E+01 37 | 35 2 0.7206071934E+01 0.3636028348E+01 -0.3119203535E+01 38 | 36 2 0.1754579401E+01 0.1345400682E+01 0.1104020920E+02 39 | 37 2 0.9128193442E+01 0.4106750681E+01 -0.1572403065E+01 40 | 38 2 0.5377745974E-02 0.2135454297E+01 0.7698800661E+01 41 | 39 2 -0.1417381560E+01 0.2093842513E+01 0.7400514063E+01 42 | 40 2 -0.2144009450E+01 0.2961244516E+01 0.6562470090E+01 43 | 41 2 -0.3502612718E+01 0.2740386696E+01 0.6369112316E+01 44 | 42 2 -0.4154554153E+01 0.1665046849E+01 0.6996007990E+01 45 | 43 2 0.3690243140E+00 0.1126270651E+01 0.8553930270E+01 46 | 44 2 0.9418171094E+00 0.3141207865E+01 0.7135707234E+01 47 | 45 2 -0.2090391908E+01 0.1023526297E+01 0.8034929041E+01 48 | 46 2 0.5543603106E+01 0.2409075869E+01 0.1273145231E+02 49 | 47 2 0.1051374853E+02 0.3887620651E+01 0.9138758625E+00 50 | 48 2 0.9940955738E+01 0.5902557865E+01 0.2332098898E+01 51 | 49 2 0.1087739510E+02 0.4896804296E+01 0.1769005471E+01 52 | 50 2 0.1230015441E+02 0.4855192513E+01 0.2067292070E+01 53 | 51 2 0.1302678230E+02 0.5722594516E+01 0.2905336042E+01 54 | 52 2 0.1438538557E+02 0.5501736696E+01 0.3098693816E+01 55 | 53 2 0.1503732700E+02 0.4426396849E+01 0.2471798142E+01 56 | 54 2 0.4922122852E+01 0.3263887030E+01 0.1181389193E+02 57 | 55 2 0.3676700875E+01 0.8746783547E+00 0.1258700964E+02 58 | 56 2 0.4915554035E+01 0.1227113453E+01 0.1312795380E+02 59 | 57 2 0.1433991499E+02 0.3556111970E+01 0.1633837445E+01 60 | 58 2 0.1297316475E+02 0.3784876298E+01 0.1432877091E+01 61 | 59 2 0.3056290501E+01 0.1725880779E+01 0.1165712193E+02 62 | 60 2 0.3676226545E+01 0.2930373404E+01 0.1128069116E+02 63 | 61 3 0.8843556474E+01 0.1821348819E+01 0.7358399198E-01 64 | 62 3 0.2039216373E+01 -0.9400011815E+00 0.9394222140E+01 65 | 63 4 0.1187443327E+02 0.2812048800E+01 0.4186976775E+00 66 | 64 4 0.2049793185E+01 0.9018902802E+00 0.9206838479E+01 67 | 65 4 0.8832979661E+01 0.3663240281E+01 0.2609676523E+00 68 | 66 4 -0.9916604235E+00 0.5069880035E-01 0.9049108455E+01 69 | 0.0000000000E+00 0.0000000000E+00 0.0000000000E+00 70 | 0.1088277285E+02 0.1000000000E-14 -0.2115593868E+01 71 | 0.0000000000E+00 0.5522700000E+01 0.0000000000E+00 72 | 0.0000000000E+00 0.0000000000E+00 0.1158340000E+02 73 | -------------------------------------------------------------------------------- /Benchmarks/README.md: -------------------------------------------------------------------------------- 1 | # Benchmarks 2 | 3 | Here is a summary of code performances. 4 | 5 | - VASP 6 | - DFTB+ 7 | - CP2K 8 | -------------------------------------------------------------------------------- /Benchmarks/VASP-Quick/INCAR: -------------------------------------------------------------------------------- 1 | System = fcc Si 2 | ISTART = 0 3 | ICHARG = 2 4 | ENCUT = 240 5 | ISMEAR = 0 6 | SIGMA = 0.1 7 | -------------------------------------------------------------------------------- /Benchmarks/VASP-Quick/KPOINTS: -------------------------------------------------------------------------------- 1 | k-points 2 | 0 3 | Monkhorst Pack 4 | 11 11 11 5 | 0 0 0 6 | -------------------------------------------------------------------------------- /Benchmarks/VASP-Quick/POSCAR: -------------------------------------------------------------------------------- 1 | fcc Si: 2 | 3.9 3 | 0.5 0.5 0.0 4 | 0.0 0.5 0.5 5 | 0.5 0.0 0.5 6 | 1 7 | cartesian 8 | 0 0 0 9 | -------------------------------------------------------------------------------- /Benchmarks/VASP-performance/INCAR: -------------------------------------------------------------------------------- 1 | INCAR created by Atomic Simulation Environment 2 | AGGAC = 0.000000 3 | KSPACING = 0.200000 4 | POTIM = 0.020000 5 | GGA = OR 6 | PREC = Accurate 7 | IBRION = 2 8 | ISIF = 3 9 | KGAMMA = .TRUE. 10 | LCHARG = .FALSE. 11 | LUSE_VDW = .TRUE. 12 | LWAVE = .FALSE. 13 | -------------------------------------------------------------------------------- /Benchmarks/VASP-performance/POSCAR: -------------------------------------------------------------------------------- 1 | C H 2 | 1.0000000000000000 3 | 7.9000000000000004 0.0000000000000000 0.0000000000000000 4 | 0.4438234745934477 6.0437257319802153 0.0000000000000000 5 | -6.1525681157834553 -2.8584023162169716 14.5015703211510960 6 | 44 28 7 | Cartesian 8 | -1.3242285103503846 -1.0530554020366913 5.9035892777406112 9 | 3.5154838691603776 4.2383788177999344 8.5979810434104849 10 | 6.3927348943282629 3.6554574888785778 4.0401374914726960 11 | -4.2014795355182706 -0.4701340731153347 10.4614328296784009 12 | -1.5061964945427213 3.8965312018337679 5.3742819610185961 13 | 3.6974518533527139 -0.7112077860705232 9.1272883601324999 14 | -0.7389271543278361 -0.1753171764688375 5.0624981991138478 15 | 2.9301825131378290 3.3606405922320817 9.4390721220372491 16 | -0.7025571455730466 -0.3518462666956115 3.6369938365446952 17 | 2.8938125043830394 3.5371696824588557 10.8645764846064008 18 | -0.0856055278214676 0.4558333470852411 2.7465974188260178 19 | 2.2768608866314612 2.7294900686780021 11.7549729023250791 20 | -0.0904063585655914 0.3032100970707062 1.3776491805093540 21 | 2.2816617173755840 2.8821133186925372 13.1239211406417429 22 | 0.6176199860485815 1.1704040632565864 0.4858026057585618 23 | 1.5736353727614103 2.0149193525066575 14.0157677153925349 24 | 7.7611857220959095 5.1400891733367402 0.8222390372092672 25 | -5.5699303632859172 -1.9547657575734969 13.6793312839418295 26 | 7.0603449225669976 4.2884052155582362 1.7764423643410092 27 | -4.8690895637570053 -1.1030817997949922 12.7251279568100859 28 | -0.8271470522367835 4.5132262532569873 3.1163874620153704 29 | 3.0184024110467762 -1.3279028374937438 11.3851828591357265 30 | 2.2301331563089448 2.3175052724147647 5.8209303269100499 31 | -0.0388777974989524 0.8678181433484785 8.6806399942410462 32 | 2.2579379916143987 3.1734843595036395 4.7652160075302499 33 | -0.0666826328044053 0.0118390562596042 9.7363543136208452 34 | 2.8791555942894171 2.8555581163443637 3.5296822161681769 35 | -0.6879002354794242 0.3297652994188804 10.9718881049829182 36 | 2.8935772713689167 3.7547251076039498 2.4449647561460748 37 | -0.7023219125589245 -0.5694016918407059 12.0566055650050217 38 | 3.5484385277032673 3.4218857027744511 1.2268328491693827 39 | -1.3571831688932749 -0.2365622870112069 13.2747374719817124 40 | 3.5977655150069685 4.2854274043253078 0.1450157032115110 41 | -1.4065101561969762 -1.1001039885620643 14.3565546179395849 42 | 4.1458629903306825 2.0774660080705338 1.0934184022147926 43 | -1.9546076315206888 1.1078574076927101 13.4081519189363032 44 | 4.0306849275102969 1.2338929047871960 2.1505828786267074 45 | -1.8394295687003039 1.9514305109760473 12.3509874425243886 46 | 3.5093428802050428 1.5377308148611599 3.3962677692135865 47 | -1.3180875213950503 1.6475926009020838 11.1053025519375090 48 | 3.3841680579471154 0.6688478364813844 4.4867858573641488 49 | -1.1929126991371224 2.5164755792818592 10.0147844637869472 50 | 2.8717182601457281 0.9855242536263399 5.6918663510518055 51 | -0.6804629013357364 2.1997991621369040 8.8097039700992905 52 | -1.3311251895179952 -0.8519457777343016 6.9897568947948283 53 | 3.5223805483279889 4.0372691934975453 7.5118134263562677 54 | 5.9385162538803984 2.7455958630542034 3.6398941506089253 55 | -3.7472608950704056 0.4397275527090400 10.8616761705421716 56 | -2.0002751191250212 3.1993033600704690 6.0906595348834598 57 | 4.1915304779350135 -0.0139799443072251 8.4109107862676371 58 | -0.2025661013094050 0.7192465082019037 5.3655810188259059 59 | 2.3938214601193972 2.4660769075613396 9.1359893023251910 60 | 0.3970074861037036 1.3169042550303494 3.1613423300109389 61 | 1.7942478727062896 1.8684191607328944 11.3402279911401571 62 | 1.0651574427400372 2.0134661736876027 0.8845957895902168 63 | 1.1260979160699542 1.1718572420756410 13.6169745315608797 64 | 6.6017615267822576 3.3763306408587668 1.4211538914728075 65 | -4.4105061679722652 -0.1910072250955231 13.0804164296782890 66 | 1.7395974617091277 2.6371616086358611 6.8882459025467702 67 | 0.4516578971008647 0.5481618071273828 7.6133244186043258 68 | 1.8487711050407531 4.1977332734464374 4.8580260575856178 69 | 0.3424842537692394 -1.0124098576831946 9.6435442635654791 70 | 2.4602007687106249 4.7673769517321070 2.5812795171648948 71 | -0.2689454099006330 -1.5820535359688634 11.9202908039862017 72 | 3.1304200596487188 5.3036166779421112 0.2900314064230219 73 | -0.9391647008387256 -2.1182932621788679 14.2115389147280737 74 | 4.4891929689164689 0.2226543472231324 2.0592229856034554 75 | -2.2979376101064748 2.9626690685401114 12.4423473355476393 76 | 3.8408757585660531 -0.3371064397157005 4.4084773776299331 77 | -1.6496203997560608 3.5224298554789448 10.0930929435211620 78 | 2.8604998643173585 0.3067310697284690 6.5692113554814471 79 | -0.6692445055073654 2.8785923460347749 7.9323589656696489 80 | -------------------------------------------------------------------------------- /Benchmarks/VASP-performance/README.md: -------------------------------------------------------------------------------- 1 | # Benchmarks 2 | 3 | ## Stampede2 4 | ``` 5 | 004: Elapsed time (sec): 1269.118 6 | 008: Elapsed time (sec): 751.434 7 | 024: Elapsed time (sec): 273.565 8 | 048: Elapsed time (sec): 183.499 9 | 096: Elapsed time (sec): 116.373 10 | 144: Elapsed time (sec): 93.578 11 | 192: Elapsed time (sec): 84.620 12 | ``` 13 | 14 | ## CMS 15 | 16 | 17 | ## CMS-2 18 | -------------------------------------------------------------------------------- /Exploring/Descriptors/README.md: -------------------------------------------------------------------------------- 1 | # Instructions 2 | 3 | ## LAMMPS Setup: 4 | 5 | ``` 6 | https://github.com/lammps/lammps.git 7 | cd lammps/src 8 | make yes-ml-snap 9 | make yes-ml-iap 10 | make mpi -j 4 11 | #make serial -j 4 12 | ``` 13 | 14 | This will generate `lmp_mpi` or `lmp_serial` under `lammps/src` 15 | 16 | ## To run lammps under this directory 17 | 18 | ``` 19 | path/lmp_serial < in.snap 20 | ``` 21 | 22 | will generate the file called `dump.sna` like the following 23 | 24 | ``` 25 | ITEM: TIMESTEP 26 | 0 27 | ITEM: NUMBER OF ATOMS 28 | 127047 29 | ITEM: BOX BOUNDS xy xz yz pp pp pp 30 | -1.1007964152930020e+02 1.1007964152930020e+02 0.0000000000000000e+00 31 | -9.2904966335464692e+01 9.2904966335464692e+01 0.0000000000000000e+00 32 | -2.4271622472917425e+01 2.4271622472917425e+01 0.0000000000000000e+00 33 | ITEM: ATOMS c_sna[1] c_sna[2] c_sna[3] c_sna[4] c_sna[5] c_sna[6] c_sna[7] c_sna[8] c_sna[9] c_sna[10] c_sna[11] c_sna[12] c_sna[13] c_sna[14] c_sna[15] c_sna[16] c_sna[17] c_sna[18] c_sna[19] c_sna[20] c_sna[21] c_sna[22] c_sna[23] c_sna[24] c_sna[25] c_sna[26] c_sna[27] c_sna[28] c_sna[29] c_sna[30] 34 | 2234.88 363.922 -53.2756 65.6995 7.00217 -9.63047 2.15077 13.605 -13.2488 -5.54597 -4.99489 -3.81596 -8.62127 41.0945 -4.42841 -9.18208 -1.51172 -6.04085 -2.32267 -11.1238 329.357 15.9159 12.7838 -2.39306 2.06609 33.3937 675.625 2.75217 3.37779 64.585 35 | ``` 36 | 37 | This will store the 30-length array for each atom to represent it local environment based on the snap descriptor. 38 | One can run clustering like PCA to identify the unique groups of atomics and check if they make sense. 39 | In future, one can try other descriptors as well. 40 | -------------------------------------------------------------------------------- /Exploring/Descriptors/in.snap: -------------------------------------------------------------------------------- 1 | # Initialize 2 | units metal 3 | dimension 3 4 | boundary p p p 5 | atom_style atomic 6 | 7 | # Read the data file 8 | read_data data.final-cunb 9 | 10 | # Define the SNAP potential 11 | pair_style lj/cut 10 12 | pair_coeff * * 1.0 1.0 13 | 14 | # compute ID group-ID snap rcutfac rfac0 twojmax R_1 R_2 ... w_1 w_2 ... keyword values ... 15 | compute sna all sna/atom 1.0 0.99363 6 3.81 3.83 1.0 0.93 16 | 17 | # Output the descriptors 18 | #dump 1 all custom 1 dump.element element 19 | dump 2 all custom 1 dump.sna c_sna[*] 20 | 21 | #dump_modify 1 element Nb 22 | # Run the simulation (dummy run if just computing descriptors) 23 | run 0 24 | -------------------------------------------------------------------------------- /Phys771/README.md: -------------------------------------------------------------------------------- 1 | # Phys771 2 | This is a repository for the Phys711 course (*Advanced Topic in Experimental and Theoretical Physics*) in Fall 2022 at UNLV. 3 | 4 | In this class, we expect to cover the following selected topics. 5 | 6 | - Elastic theory to investigate both hard and soft materials 7 | - Modern global optimization methods applied to the structure prediction 8 | - Displacive phase transition 9 | 10 | The class will be organized in the `project-oriented` manner. The students will be split into different working groups according to their interests. Each working group will go over the following three phases: 11 | 12 | - Start with the assigned literature and then give weekly presentation (weeks 1-4). 13 | - Upon the feedback from the in-class discussion, each group will continue to explore the in-depth topics and conduct a short research project. The progress of each project needs to be updated on the weekly basis (week 5-10). 14 | - Write a report to summarize the key results. 15 | 16 | ## Short description of each topic 17 | 18 | ### Elastic theory and its application 19 | 20 | In the topic, we are aimed to overview the fundamental elastic theory and apply it to investigate the crystalline materials. 21 | 22 | 1. The fundamental of elastic theory (elastic constants as a tensor) 23 | 2. Elastic properties (bulk modulus, Poisson’s ration, .etc), how to compute/measure them? 24 | 3. Analysis of elastic properties 25 | * averaging scheme 26 | * anisotropic analysis 27 | 4. Applications to metals, ceramics and organic crystals 28 | 29 | **Reading assignments** 30 | 31 | - [Fundamental and technical implementation](https://www.sciencedirect.com/science/article/pii/S0010465510003401?via%3Dihub) 32 | - [Inorganic crystalline compounds](https://www.nature.com/articles/sdata20159) 33 | - [Organic crystals](https://onlinelibrary.wiley.com/doi/10.1002/anie.202113988) 34 | - [A cool online visualization tool](http://progs.coudert.name/elate) 35 | - [Negative Poisson Ratio 1](https://www.science.org/doi/10.1126/science.279.5356.1522) 36 | - [Negative Poisson Ratio 2](https://www.nature.com/articles/32842) 37 | 38 | ### Modern global optimization methods applied to structure prediction 39 | 40 | We will review different global optimization techniques that have been applied to the prediction of materials and proteins. In particular, we will focus on 41 | 42 | 1. Recent progress in protein structure prediction 43 | 2. Necessary technical implementations used in structure prediction 44 | 3. a comparative study between the protein and cluster structure predictions. 45 | 46 | **Reading assignments** 47 | 48 | - [Basin Hopping for cluster structure prediction](http://doye.chem.ox.ac.uk/abstracts/jpc97.html) 49 | - [Protein structure prediction with AlphaFold](https://www.nature.com/articles/s41586-021-03819-2) 50 | - [Online database of protein](https://alphafold.ebi.ac.uk) 51 | - [Online database of cluster](https://www-wales.ch.cam.ac.uk/CCD.html) 52 | 53 | ### Displacive phase transition 54 | We will focus the special type of phase transition that is driven by small atomic displacements. 55 | 56 | 1. Landaus’ theory on 2nd-order phase transition 57 | 2. Order parameters for describing different kinds of phase transitions 58 | 3. Group-subgroup symmetry relation in their crystal structures. 59 | 4. Designing new ferroelectric and piezoelectric materials. 60 | 61 | **Reading assignments** 62 | 63 | - [Fundamental Theory](http://www.damtp.cam.ac.uk/user/tong/statphys/five.pdf) 64 | - [Symmetry relation](https://journals.aps.org/prb/abstract/10.1103/PhysRevB.2.754) 65 | - [Applications to organic ferroelectrics](http://dx.doi.org/10.1039/C5CS00308C) 66 | - [Modern polarization theory](https://www.sciencedirect.com/science/article/pii/S0022459612003234) 67 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CMS 2 | Some ongoing projects in Zhu's group. It will post some shared scripts and lecture notes. 3 | 4 | Please also check the [group wiki page](https://github.com/qzhu2017/CMS/wiki) for group meeting and annoucements. 5 | -------------------------------------------------------------------------------- /Scripts/ASE/Demo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 1, 6 | "metadata": {}, 7 | "outputs": [], 8 | "source": [ 9 | "from ase.io import read, write\n", 10 | "from ase import Atoms\n", 11 | "\n", 12 | "struc = read('gra.vasp',format='vasp')" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 3, 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [ 21 | "from ase.build import surface\n", 22 | "s1 = surface(struc, (1,1,0), layers=2)" 23 | ] 24 | }, 25 | { 26 | "cell_type": "code", 27 | "execution_count": 4, 28 | "metadata": {}, 29 | "outputs": [ 30 | { 31 | "data": { 32 | "text/plain": [ 33 | "array([[ 5.21976843e-17, 7.50000000e-01, 0.00000000e+00],\n", 34 | " [ 0.00000000e+00, 2.50000000e-01, 0.00000000e+00],\n", 35 | " [ 3.33333330e-01, 7.50000000e-01, 0.00000000e+00],\n", 36 | " [ 6.66666670e-01, 2.50000000e-01, 0.00000000e+00],\n", 37 | " [ 5.00000000e-01, 7.50000000e-01, 1.22800000e+00],\n", 38 | " [ 5.00000000e-01, 2.50000000e-01, 1.22800000e+00],\n", 39 | " [ 8.33333330e-01, 7.50000000e-01, 1.22800000e+00],\n", 40 | " [ 1.66666670e-01, 2.50000000e-01, 1.22800000e+00]])" 41 | ] 42 | }, 43 | "execution_count": 4, 44 | "metadata": {}, 45 | "output_type": "execute_result" 46 | } 47 | ], 48 | "source": [ 49 | "s1.get_scaled_positions()" 50 | ] 51 | }, 52 | { 53 | "cell_type": "code", 54 | "execution_count": 5, 55 | "metadata": {}, 56 | "outputs": [], 57 | "source": [ 58 | "write('POSCAR',s1, format='vasp')" 59 | ] 60 | }, 61 | { 62 | "cell_type": "code", 63 | "execution_count": 6, 64 | "metadata": {}, 65 | "outputs": [], 66 | "source": [ 67 | "from ase.build.supercells import make_supercell\n", 68 | "import numpy as np\n", 69 | "\n", 70 | "P = np.array([[1,-1,0],[1,1,0],[0,0,1]])*10\n", 71 | "s = make_supercell(struc, P)\n" 72 | ] 73 | }, 74 | { 75 | "cell_type": "code", 76 | "execution_count": 7, 77 | "metadata": {}, 78 | "outputs": [ 79 | { 80 | "data": { 81 | "text/plain": [ 82 | "Atoms(symbols='C8000', pbc=True, cell=[[0.0, -42.5391678, 0.0], [24.56, 0.0, 0.0], [0.0, 0.0, 67.1]])" 83 | ] 84 | }, 85 | "execution_count": 7, 86 | "metadata": {}, 87 | "output_type": "execute_result" 88 | } 89 | ], 90 | "source": [ 91 | "s" 92 | ] 93 | }, 94 | { 95 | "cell_type": "code", 96 | "execution_count": null, 97 | "metadata": { 98 | "collapsed": true 99 | }, 100 | "outputs": [], 101 | "source": [ 102 | "#write('new.gen',s, format='gen')" 103 | ] 104 | }, 105 | { 106 | "cell_type": "code", 107 | "execution_count": null, 108 | "metadata": { 109 | "collapsed": true 110 | }, 111 | "outputs": [], 112 | "source": [] 113 | } 114 | ], 115 | "metadata": { 116 | "kernelspec": { 117 | "display_name": "Python 3", 118 | "language": "python", 119 | "name": "python3" 120 | }, 121 | "language_info": { 122 | "codemirror_mode": { 123 | "name": "ipython", 124 | "version": 3 125 | }, 126 | "file_extension": ".py", 127 | "mimetype": "text/x-python", 128 | "name": "python", 129 | "nbconvert_exporter": "python", 130 | "pygments_lexer": "ipython3", 131 | "version": "3.6.0" 132 | } 133 | }, 134 | "nbformat": 4, 135 | "nbformat_minor": 2 136 | } 137 | -------------------------------------------------------------------------------- /Scripts/ASE/Model_construction.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 14, 6 | "metadata": { 7 | "collapsed": true 8 | }, 9 | "outputs": [], 10 | "source": [ 11 | "from ase.cluster import Octahedron\n", 12 | "au_55 = Octahedron('Au', 5, cutoff=2)" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 6, 18 | "metadata": { 19 | "collapsed": true 20 | }, 21 | "outputs": [], 22 | "source": [ 23 | "from ase.build import bulk\n", 24 | "cu = bulk('Cu','fcc',a=3.6)" 25 | ] 26 | }, 27 | { 28 | "cell_type": "code", 29 | "execution_count": 10, 30 | "metadata": { 31 | "collapsed": true 32 | }, 33 | "outputs": [], 34 | "source": [ 35 | "from ase.build import molecule\n", 36 | "water = molecule('H2O')\n" 37 | ] 38 | }, 39 | { 40 | "cell_type": "code", 41 | "execution_count": 17, 42 | "metadata": { 43 | "collapsed": true 44 | }, 45 | "outputs": [], 46 | "source": [ 47 | "from ase import Atoms\n", 48 | "au = Atoms(au_55) #x3d view function is only suppored for atoms class" 49 | ] 50 | }, 51 | { 52 | "cell_type": "code", 53 | "execution_count": 26, 54 | "metadata": {}, 55 | "outputs": [ 56 | { 57 | "data": { 58 | "text/html": [ 59 | "\n", 60 | " \n", 61 | " ASE atomic visualization\n", 62 | " \n", 64 | " \n", 65 | " \n", 68 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | " \n", 100 | " \n", 101 | " \n", 102 | " \n", 103 | " \n", 104 | " \n", 105 | "\n" 106 | ], 107 | "text/plain": [ 108 | "" 109 | ] 110 | }, 111 | "execution_count": 26, 112 | "metadata": {}, 113 | "output_type": "execute_result" 114 | } 115 | ], 116 | "source": [ 117 | "from ase.visualize import view\n", 118 | "view(water, viewer='x3d', repeat=[2,2,2])" 119 | ] 120 | }, 121 | { 122 | "cell_type": "code", 123 | "execution_count": 28, 124 | "metadata": {}, 125 | "outputs": [ 126 | { 127 | "name": "stdout", 128 | "output_type": "stream", 129 | "text": [ 130 | "Help on function view in module ase.visualize:\n", 131 | "\n", 132 | "view(atoms, data=None, viewer='ase', repeat=None, block=False)\n", 133 | "\n" 134 | ] 135 | } 136 | ], 137 | "source": [ 138 | "help(view)\n", 139 | "#ASE gui is more powerful!" 140 | ] 141 | }, 142 | { 143 | "cell_type": "code", 144 | "execution_count": null, 145 | "metadata": { 146 | "collapsed": true 147 | }, 148 | "outputs": [], 149 | "source": [ 150 | "#some file read/write function will be followed" 151 | ] 152 | }, 153 | { 154 | "cell_type": "code", 155 | "execution_count": 4, 156 | "metadata": {}, 157 | "outputs": [ 158 | { 159 | "name": "stdout", 160 | "output_type": "stream", 161 | "text": [ 162 | "['PH3', 'P2', 'CH3CHO', 'H2COH', 'CS', 'OCHCHO', 'C3H9C', 'CH3COF', 'CH3CH2OCH3', 'HCOOH', 'HCCl3', 'HOCl', 'H2', 'SH2', 'C2H2', 'C4H4NH', 'CH3SCH3', 'SiH2_s3B1d', 'CH3SH', 'CH3CO', 'CO', 'ClF3', 'SiH4', 'C2H6CHOH', 'CH2NHCH2', 'isobutene', 'HCO', 'bicyclobutane', 'LiF', 'Si', 'C2H6', 'CN', 'ClNO', 'S', 'SiF4', 'H3CNH2', 'methylenecyclopropane', 'CH3CH2OH', 'F', 'NaCl', 'CH3Cl', 'CH3SiH3', 'AlF3', 'C2H3', 'ClF', 'PF3', 'PH2', 'CH3CN', 'cyclobutene', 'CH3ONO', 'SiH3', 'C3H6_D3h', 'CO2', 'NO', 'trans-butane', 'H2CCHCl', 'LiH', 'NH2', 'CH', 'CH2OCH2', 'C6H6', 'CH3CONH2', 'cyclobutane', 'H2CCHCN', 'butadiene', 'C', 'H2CO', 'CH3COOH', 'HCF3', 'CH3S', 'CS2', 'SiH2_s1A1d', 'C4H4S', 'N2H4', 'OH', 'CH3OCH3', 'C5H5N', 'H2O', 'HCl', 'CH2_s1A1d', 'CH3CH2SH', 'CH3NO2', 'Cl', 'Be', 'BCl3', 'C4H4O', 'Al', 'CH3O', 'CH3OH', 'C3H7Cl', 'isobutane', 'Na', 'CCl4', 'CH3CH2O', 'H2CCHF', 'C3H7', 'CH3', 'O3', 'P', 'C2H4', 'NCCN', 'S2', 'AlCl3', 'SiCl4', 'SiO', 'C3H4_D2d', 'H', 'COF2', '2-butyne', 'C2H5', 'BF3', 'N2O', 'F2O', 'SO2', 'H2CCl2', 'CF3CN', 'HCN', 'C2H6NH', 'OCS', 'B', 'ClO', 'C3H8', 'HF', 'O2', 'SO', 'NH', 'C2F4', 'NF3', 'CH2_s3B1d', 'CH3CH2Cl', 'CH3COCl', 'NH3', 'C3H9N', 'CF4', 'C3H6_Cs', 'Si2H6', 'HCOOCH3', 'O', 'CCH', 'N', 'Si2', 'C2H6SO', 'C5H8', 'H2CF2', 'Li2', 'CH2SCH2', 'C2Cl4', 'C3H4_C3v', 'CH3COCH3', 'F2', 'CH4', 'SH', 'H2CCO', 'CH3CH2NH2', 'Li', 'N2', 'Cl2', 'H2O2', 'Na2', 'BeH', 'C3H4_C2v', 'NO2']\n" 163 | ] 164 | } 165 | ], 166 | "source": [ 167 | "from ase.build import molecule\n", 168 | "from ase.collections import g2\n", 169 | "print(g2.names)\n" 170 | ] 171 | }, 172 | { 173 | "cell_type": "code", 174 | "execution_count": 5, 175 | "metadata": { 176 | "collapsed": true 177 | }, 178 | "outputs": [], 179 | "source": [ 180 | "c60 = molecule('C60')" 181 | ] 182 | }, 183 | { 184 | "cell_type": "code", 185 | "execution_count": 7, 186 | "metadata": {}, 187 | "outputs": [], 188 | "source": [ 189 | "from ase.visualize import view\n", 190 | "\n", 191 | "view(c60)" 192 | ] 193 | }, 194 | { 195 | "cell_type": "code", 196 | "execution_count": 9, 197 | "metadata": {}, 198 | "outputs": [ 199 | { 200 | "data": { 201 | "text/plain": [ 202 | "array([[ 2.2101953, 0.5866631, 2.6669504],\n", 203 | " [ 3.1076393, 0.1577008, 1.6300286],\n", 204 | " [ 1.328443 , -0.3158939, 3.2363232],\n", 205 | " [ 3.0908709, -1.1585005, 1.201424 ],\n", 206 | " [ 3.1879245, -1.4574599, -0.1997005],\n", 207 | " [ 3.2214623, 1.2230966, 0.673944 ],\n", 208 | " [ 3.316121 , 0.9351586, -0.6765151],\n", 209 | " [ 3.2984981, -0.4301142, -1.1204138],\n", 210 | " [-0.4480842, 1.3591484, 3.208102 ],\n", 211 | " [ 0.4672056, 2.294983 , 2.6175264],\n", 212 | " [-0.0256575, 0.0764219, 3.5086259],\n", 213 | " [ 1.7727917, 1.9176584, 2.3529691],\n", 214 | " [ 2.3954623, 2.3095689, 1.1189539],\n", 215 | " [-0.2610195, 3.0820935, 1.6623117],\n", 216 | " [ 0.3407726, 3.4592388, 0.4745968],\n", 217 | " [ 1.6951171, 3.0692446, 0.1976623],\n", 218 | " [-2.1258394, -0.8458853, 2.6700963],\n", 219 | " [-2.562099 , 0.4855202, 2.3531715],\n", 220 | " [-0.8781521, -1.0461985, 3.2367302],\n", 221 | " [-1.7415096, 1.5679963, 2.6197333],\n", 222 | " [-1.6262468, 2.635703 , 1.6641811],\n", 223 | " [-3.298481 , 0.4301871, 1.1204208],\n", 224 | " [-3.1879469, 1.4573895, 0.199603 ],\n", 225 | " [-2.3360261, 2.5813627, 0.4760912],\n", 226 | " [-0.500521 , -2.9797771, 1.7940308],\n", 227 | " [-1.7944338, -2.7729087, 1.2047891],\n", 228 | " [-0.0514245, -2.1328841, 2.793883 ],\n", 229 | " [-2.5891471, -1.7225828, 1.6329715],\n", 230 | " [-3.3160705, -0.9350636, 0.6765268],\n", 231 | " [-1.6951919, -3.0692581, -0.1976564],\n", 232 | " [-2.3954901, -2.3096853, -1.1189862],\n", 233 | " [-3.2214182, -1.2231835, -0.6739581],\n", 234 | " [ 2.1758234, -2.0946263, 1.7922529],\n", 235 | " [ 1.7118619, -2.9749681, 0.7557198],\n", 236 | " [ 1.3130656, -1.6829416, 2.7943892],\n", 237 | " [ 0.3959024, -3.4051395, 0.7557638],\n", 238 | " [-0.3408219, -3.4591883, -0.474561 ],\n", 239 | " [ 2.3360057, -2.5814499, -0.476105 ],\n", 240 | " [ 1.6263757, -2.6357349, -1.6642309],\n", 241 | " [ 0.2611352, -3.0821271, -1.6622618],\n", 242 | " [-2.2100844, -0.5868636, -2.66703 ],\n", 243 | " [-1.772697 , -1.9178969, -2.3530466],\n", 244 | " [-0.4670723, -2.2950509, -2.6175105],\n", 245 | " [-1.32835 , 0.3157683, -3.2362375],\n", 246 | " [-2.1759882, 2.0945383, -1.7923294],\n", 247 | " [-3.0909663, 1.1583472, -1.2015749],\n", 248 | " [-3.107609 , -0.1578453, -1.6301627],\n", 249 | " [-1.3131365, 1.6828292, -2.7943639],\n", 250 | " [ 0.5003224, 2.9799637, -1.7940203],\n", 251 | " [-0.3961148, 3.4052817, -0.7557272],\n", 252 | " [-1.7120629, 2.9749122, -0.7557988],\n", 253 | " [ 0.0512824, 2.1329478, -2.793745 ],\n", 254 | " [ 2.125863 , 0.8460809, -2.6700534],\n", 255 | " [ 2.5891853, 1.7227742, -1.6329562],\n", 256 | " [ 1.794301 , 2.7730684, -1.2048262],\n", 257 | " [ 0.8781323, 1.0463514, -3.2365313],\n", 258 | " [ 0.4482452, -1.3591061, -3.208051 ],\n", 259 | " [ 1.7416948, -1.5679557, -2.6197714],\n", 260 | " [ 2.5621724, -0.4853529, -2.3532026],\n", 261 | " [ 0.0257904, -0.0763567, -3.5084446]])" 262 | ] 263 | }, 264 | "execution_count": 9, 265 | "metadata": {}, 266 | "output_type": "execute_result" 267 | } 268 | ], 269 | "source": [ 270 | "c60.get_positions()" 271 | ] 272 | }, 273 | { 274 | "cell_type": "code", 275 | "execution_count": null, 276 | "metadata": { 277 | "collapsed": true 278 | }, 279 | "outputs": [], 280 | "source": [] 281 | } 282 | ], 283 | "metadata": { 284 | "kernelspec": { 285 | "display_name": "Python 3", 286 | "language": "python", 287 | "name": "python3" 288 | }, 289 | "language_info": { 290 | "codemirror_mode": { 291 | "name": "ipython", 292 | "version": 3 293 | }, 294 | "file_extension": ".py", 295 | "mimetype": "text/x-python", 296 | "name": "python", 297 | "nbconvert_exporter": "python", 298 | "pygments_lexer": "ipython3", 299 | "version": "3.6.0" 300 | } 301 | }, 302 | "nbformat": 4, 303 | "nbformat_minor": 2 304 | } 305 | -------------------------------------------------------------------------------- /Scripts/ASE/gra.vasp: -------------------------------------------------------------------------------- 1 | graphite 2 | 1.0 3 | 1.22800000 -2.12695839 0.00000000 4 | 1.22800000 2.12695839 0.00000000 5 | 0.00000000 0.00000000 6.71000000 6 | C 7 | 4 8 | direct 9 | 0.00000000 0.00000000 0.25000000 10 | 0.00000000 0.00000000 0.75000000 11 | 0.33333333 0.66666667 0.25000000 12 | 0.66666667 0.33333333 0.75000000 13 | -------------------------------------------------------------------------------- /Scripts/ASE/supercell.py: -------------------------------------------------------------------------------- 1 | from ase.io import read, write 2 | from ase import Atoms 3 | from ase import geometry 4 | from ase.build.supercells import make_supercell 5 | import numpy as np 6 | 7 | #Read structure from POSCAR, this is ase.atom object 8 | struc = read('gra.vasp',format='vasp') 9 | 10 | #make supercell here 11 | P = np.array([[1,-1,0],[1,1,0],[0,0,1]])*2 12 | gra1 = make_supercell(struc, P) 13 | 14 | #After the lattice transformation 15 | #the supercell might have unpleasant shape 16 | #let's apply another transformation here 17 | cell_par = gra1.get_cell_lengths_and_angles() 18 | pos1 = gra1.get_scaled_positions() 19 | cell1 = geometry.cell.cellpar_to_cell(cell_par) 20 | gra1.set_cell(cell1) 21 | gra1.set_scaled_positions(pos1) 22 | 23 | #output in any format whichever you want 24 | write('POSCAR',gra1, format='vasp') 25 | -------------------------------------------------------------------------------- /Scripts/Aflow/demo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Extracting data from AFLOWlib\n", 8 | "\n", 9 | "Here is a simple example to extract data from aflowlib by using [aflow Python library](https://pypi.python.org/pypi/aflow)" 10 | ] 11 | }, 12 | { 13 | "cell_type": "code", 14 | "execution_count": 1, 15 | "metadata": {}, 16 | "outputs": [ 17 | { 18 | "name": "stdout", 19 | "output_type": "stream", 20 | "text": [ 21 | "621\n" 22 | ] 23 | } 24 | ], 25 | "source": [ 26 | "from aflow import *\n", 27 | "\n", 28 | "results = search(batch_size=20\n", 29 | " ).filter((K.Egap > 0.1) & (K.Egap < 1)\n", 30 | " ).filter(K.nspecies == 2\n", 31 | " ).filter(K.natoms < 5)\n", 32 | "print(len(results))" 33 | ] 34 | }, 35 | { 36 | "cell_type": "code", 37 | "execution_count": 2, 38 | "metadata": { 39 | "scrolled": false 40 | }, 41 | "outputs": [ 42 | { 43 | "data": { 44 | "text/plain": [ 45 | "['Bravais_lattice_orig',\n", 46 | " 'Bravais_lattice_relax',\n", 47 | " 'Egap',\n", 48 | " 'Egap_fit',\n", 49 | " 'Egap_type',\n", 50 | " 'PV_atom',\n", 51 | " 'PV_cell',\n", 52 | " 'Pearson_symbol_orig',\n", 53 | " 'Pearson_symbol_relax',\n", 54 | " 'Pulay_stress',\n", 55 | " 'Pullay_stress',\n", 56 | " '__class__',\n", 57 | " '__delattr__',\n", 58 | " '__dict__',\n", 59 | " '__dir__',\n", 60 | " '__doc__',\n", 61 | " '__eq__',\n", 62 | " '__format__',\n", 63 | " '__ge__',\n", 64 | " '__getattribute__',\n", 65 | " '__gt__',\n", 66 | " '__hash__',\n", 67 | " '__init__',\n", 68 | " '__init_subclass__',\n", 69 | " '__le__',\n", 70 | " '__lt__',\n", 71 | " '__module__',\n", 72 | " '__ne__',\n", 73 | " '__new__',\n", 74 | " '__reduce__',\n", 75 | " '__reduce_ex__',\n", 76 | " '__repr__',\n", 77 | " '__setattr__',\n", 78 | " '__sizeof__',\n", 79 | " '__str__',\n", 80 | " '__subclasshook__',\n", 81 | " '__weakref__',\n", 82 | " '_atoms',\n", 83 | " '_files',\n", 84 | " '_lazy_load',\n", 85 | " 'ael_bulk_modulus_reuss',\n", 86 | " 'ael_bulk_modulus_voigt',\n", 87 | " 'ael_bulk_modulus_vrh',\n", 88 | " 'ael_elastic_anistropy',\n", 89 | " 'ael_poisson_ratio',\n", 90 | " 'ael_shear_modulus_reuss',\n", 91 | " 'ael_shear_modulus_voigt',\n", 92 | " 'ael_shear_modulus_vrh',\n", 93 | " 'aflow_version',\n", 94 | " 'aflowlib_date',\n", 95 | " 'aflowlib_entries',\n", 96 | " 'aflowlib_entries_number',\n", 97 | " 'aflowlib_version',\n", 98 | " 'agl_acoustic_debye',\n", 99 | " 'agl_bulk_modulus_isothermal_300K',\n", 100 | " 'agl_bulk_modulus_static_300K',\n", 101 | " 'agl_debye',\n", 102 | " 'agl_gruneisen',\n", 103 | " 'agl_heat_capacity_Cp_300K',\n", 104 | " 'agl_heat_capacity_Cv_300K',\n", 105 | " 'agl_thermal_conductivity_300K',\n", 106 | " 'agl_thermal_expansion_300K',\n", 107 | " 'atoms',\n", 108 | " 'attributes',\n", 109 | " 'auid',\n", 110 | " 'aurl',\n", 111 | " 'author',\n", 112 | " 'bader_atomic_volumes',\n", 113 | " 'bader_net_charges',\n", 114 | " 'calculation_cores',\n", 115 | " 'calculation_memory',\n", 116 | " 'calculation_time',\n", 117 | " 'catalog',\n", 118 | " 'code',\n", 119 | " 'composition',\n", 120 | " 'compound',\n", 121 | " 'corresponding',\n", 122 | " 'data_api',\n", 123 | " 'data_language',\n", 124 | " 'data_source',\n", 125 | " 'delta_electronic_energy_convergence',\n", 126 | " 'delta_electronic_energy_threshold',\n", 127 | " 'density',\n", 128 | " 'dft_type',\n", 129 | " 'eentropy_atom',\n", 130 | " 'eentropy_cell',\n", 131 | " 'energy_atom',\n", 132 | " 'energy_cell',\n", 133 | " 'energy_cutoff',\n", 134 | " 'enthalpy_atom',\n", 135 | " 'enthalpy_cell',\n", 136 | " 'enthalpy_formation_atom',\n", 137 | " 'enthalpy_formation_cell',\n", 138 | " 'entropic_temperature',\n", 139 | " 'files',\n", 140 | " 'forces',\n", 141 | " 'geometry',\n", 142 | " 'keywords',\n", 143 | " 'kpoints',\n", 144 | " 'lattice_system_orig',\n", 145 | " 'lattice_system_relax',\n", 146 | " 'lattice_variation_orig',\n", 147 | " 'lattice_variation_relax',\n", 148 | " 'ldau_TLUJ',\n", 149 | " 'loop',\n", 150 | " 'natoms',\n", 151 | " 'nbondxx',\n", 152 | " 'node_CPU_Cores',\n", 153 | " 'node_CPU_MHz',\n", 154 | " 'node_CPU_Model',\n", 155 | " 'node_RAM_GB',\n", 156 | " 'nspecies',\n", 157 | " 'positions_cartesian',\n", 158 | " 'positions_fractional',\n", 159 | " 'pressure',\n", 160 | " 'pressure_final',\n", 161 | " 'pressure_residual',\n", 162 | " 'prototype',\n", 163 | " 'raw',\n", 164 | " 'scintillation_attenuation_length',\n", 165 | " 'sg',\n", 166 | " 'sg2',\n", 167 | " 'spacegroup_orig',\n", 168 | " 'spacegroup_relax',\n", 169 | " 'species',\n", 170 | " 'species_pp',\n", 171 | " 'species_pp_ZVAL',\n", 172 | " 'species_pp_version',\n", 173 | " 'spinD',\n", 174 | " 'spinF',\n", 175 | " 'spin_atom',\n", 176 | " 'spin_cell',\n", 177 | " 'sponsor',\n", 178 | " 'stoich',\n", 179 | " 'stoichiometry',\n", 180 | " 'stress_tensor',\n", 181 | " 'valence_cell_iupac',\n", 182 | " 'valence_cell_std',\n", 183 | " 'volume_atom',\n", 184 | " 'volume_cell']" 185 | ] 186 | }, 187 | "execution_count": 2, 188 | "metadata": {}, 189 | "output_type": "execute_result" 190 | } 191 | ], 192 | "source": [ 193 | "# what kind of data does each entry have?\n", 194 | "dir(results[0])" 195 | ] 196 | }, 197 | { 198 | "cell_type": "code", 199 | "execution_count": 3, 200 | "metadata": {}, 201 | "outputs": [ 202 | { 203 | "name": "stdout", 204 | "output_type": "stream", 205 | "text": [ 206 | "Progress 100 / 621 Bi2Te3 0.277\n", 207 | "Progress 200 / 621 Bi2Se3 0.3929\n" 208 | ] 209 | } 210 | ], 211 | "source": [ 212 | "counter=0\n", 213 | "\n", 214 | "for result in results[:200]:\n", 215 | " counter += 1\n", 216 | " if (counter % 100==0):\n", 217 | " print('Progress', counter, \"/\", len(results), result.compound, result.Egap)\n" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 4, 223 | "metadata": { 224 | "scrolled": false 225 | }, 226 | "outputs": [ 227 | { 228 | "name": "stdout", 229 | "output_type": "stream", 230 | "text": [ 231 | "Bi2O3\n", 232 | "[ 3.917021 3.917021 5.849795 90. 90. 90. ]\n", 233 | "Bi2O3_ICSD_168808\n", 234 | "\n", 235 | "aflowlib.duke.edu:AFLOWDATA/ICSD_WEB/TET/Bi2O3_ICSD_168808\n" 236 | ] 237 | } 238 | ], 239 | "source": [ 240 | "print(results[0].compound)\n", 241 | "print(results[0].geometry)\n", 242 | "print(results[0].prototype)\n", 243 | "print(results[0].aurl)" 244 | ] 245 | }, 246 | { 247 | "cell_type": "code", 248 | "execution_count": 5, 249 | "metadata": {}, 250 | "outputs": [ 251 | { 252 | "name": "stdout", 253 | "output_type": "stream", 254 | "text": [ 255 | "['AECCAR0.static.xz',\n", 256 | " 'AECCAR2.static.xz',\n", 257 | " 'Bi2O3_ICSD_168808.cif',\n", 258 | " 'Bi2O3_ICSD_168808.png',\n", 259 | " 'Bi2O3_ICSD_168808_BZ.png',\n", 260 | " 'Bi2O3_ICSD_168808_Bader_20_Bi.jvxl.xz',\n", 261 | " 'Bi2O3_ICSD_168808_Bader_20_O.jvxl.xz',\n", 262 | " 'Bi2O3_ICSD_168808_Bader_30_Bi.jvxl.xz',\n", 263 | " 'Bi2O3_ICSD_168808_Bader_30_O.jvxl.xz',\n", 264 | " 'Bi2O3_ICSD_168808_Bader_40_Bi.jvxl.xz',\n", 265 | " 'Bi2O3_ICSD_168808_Bader_40_O.jvxl.xz',\n", 266 | " 'Bi2O3_ICSD_168808_Bader_50_Bi.jvxl.xz',\n", 267 | " 'Bi2O3_ICSD_168808_Bader_50_O.jvxl.xz',\n", 268 | " 'Bi2O3_ICSD_168808_DOS.png',\n", 269 | " 'Bi2O3_ICSD_168808_PEDOS_1_5_Bi.png',\n", 270 | " 'Bi2O3_ICSD_168808_PEDOS_3_5_O.png',\n", 271 | " 'Bi2O3_ICSD_168808_PEDOS_4_5_O.png',\n", 272 | " 'Bi2O3_ICSD_168808_PEDOS_5_5_O.png',\n", 273 | " 'Bi2O3_ICSD_168808_abader.out',\n", 274 | " 'Bi2O3_ICSD_168808_bandsdata.json.xz',\n", 275 | " 'Bi2O3_ICSD_168808_corner.cif',\n", 276 | " 'Bi2O3_ICSD_168808_dosdata.json.xz',\n", 277 | " 'Bi2O3_ICSD_168808_sconv.cif',\n", 278 | " 'Bi2O3_ICSD_168808_sconv_corner.cif',\n", 279 | " 'Bi2O3_ICSD_168808_sprim.cif',\n", 280 | " 'Bi2O3_ICSD_168808_sprim_corner.cif',\n", 281 | " 'Bi2O3_ICSD_168808_structure_relax.json',\n", 282 | " 'Bi2O3_ICSD_168808_structure_relax1.json',\n", 283 | " 'CHGCAR.static.xz',\n", 284 | " 'CONTCAR.relax',\n", 285 | " 'CONTCAR.relax.abinit',\n", 286 | " 'CONTCAR.relax.aims',\n", 287 | " 'CONTCAR.relax.qe',\n", 288 | " 'CONTCAR.relax.vasp',\n", 289 | " 'CONTCAR.relax1',\n", 290 | " 'DOSCAR.static.xz',\n", 291 | " 'EIGENVAL.bands.xz',\n", 292 | " 'INCAR.bands',\n", 293 | " 'KPOINTS.bands',\n", 294 | " 'KPOINTS.relax',\n", 295 | " 'KPOINTS.static',\n", 296 | " 'OUTCAR.static.xz',\n", 297 | " 'POSCAR.bands',\n", 298 | " 'aflow.agroup.bands.json.xz',\n", 299 | " 'aflow.agroup.bands.out.xz',\n", 300 | " 'aflow.agroup.orig.json.xz',\n", 301 | " 'aflow.agroup.orig.out.xz',\n", 302 | " 'aflow.agroup.relax.json.xz',\n", 303 | " 'aflow.agroup.relax.out.xz',\n", 304 | " 'aflow.fgroup.bands.json.xz',\n", 305 | " 'aflow.fgroup.bands.out.xz',\n", 306 | " 'aflow.fgroup.orig.json.xz',\n", 307 | " 'aflow.fgroup.orig.out.xz',\n", 308 | " 'aflow.fgroup.relax.json.xz',\n", 309 | " 'aflow.fgroup.relax.out.xz',\n", 310 | " 'aflow.iatoms.bands.json.xz',\n", 311 | " 'aflow.iatoms.bands.out.xz',\n", 312 | " 'aflow.iatoms.orig.json.xz',\n", 313 | " 'aflow.iatoms.orig.out.xz',\n", 314 | " 'aflow.iatoms.relax.json.xz',\n", 315 | " 'aflow.iatoms.relax.out.xz',\n", 316 | " 'aflow.pgroup.bands.json.xz',\n", 317 | " 'aflow.pgroup.bands.out.xz',\n", 318 | " 'aflow.pgroup.orig.json.xz',\n", 319 | " 'aflow.pgroup.orig.out.xz',\n", 320 | " 'aflow.pgroup.relax.json.xz',\n", 321 | " 'aflow.pgroup.relax.out.xz',\n", 322 | " 'aflow.pgroup_xtal.bands.json.xz',\n", 323 | " 'aflow.pgroup_xtal.bands.out.xz',\n", 324 | " 'aflow.pgroup_xtal.orig.json.xz',\n", 325 | " 'aflow.pgroup_xtal.orig.out.xz',\n", 326 | " 'aflow.pgroup_xtal.relax.json.xz',\n", 327 | " 'aflow.pgroup_xtal.relax.out.xz',\n", 328 | " 'aflow.pgroupk.bands.json.xz',\n", 329 | " 'aflow.pgroupk.bands.out.xz',\n", 330 | " 'aflow.pgroupk.orig.json.xz',\n", 331 | " 'aflow.pgroupk.orig.out.xz',\n", 332 | " 'aflow.pgroupk.relax.json.xz',\n", 333 | " 'aflow.pgroupk.relax.out.xz',\n", 334 | " 'aflow.pgroupk_xtal.bands.json.xz',\n", 335 | " 'aflow.pgroupk_xtal.bands.out.xz',\n", 336 | " 'aflow.pgroupk_xtal.orig.json.xz',\n", 337 | " 'aflow.pgroupk_xtal.orig.out.xz',\n", 338 | " 'aflow.pgroupk_xtal.relax.json.xz',\n", 339 | " 'aflow.pgroupk_xtal.relax.out.xz',\n", 340 | " 'aflowlib.json',\n", 341 | " 'aflowlib.out',\n", 342 | " 'edata.bands.json',\n", 343 | " 'edata.bands.out',\n", 344 | " 'edata.orig.json',\n", 345 | " 'edata.orig.out',\n", 346 | " 'edata.relax.json',\n", 347 | " 'edata.relax.out',\n", 348 | " 'index.php\\n']\n" 349 | ] 350 | } 351 | ], 352 | "source": [ 353 | "from pprint import pprint\n", 354 | "pprint(results[0].files)\n" 355 | ] 356 | }, 357 | { 358 | "cell_type": "markdown", 359 | "metadata": {}, 360 | "source": [ 361 | "More illustration: here is [an example from my student](https://github.com/katieran4/Machine-Learning/blob/master/M4_V4-Predicting%20Band%20Gap_DavidTest.ipynb)" 362 | ] 363 | }, 364 | { 365 | "cell_type": "code", 366 | "execution_count": null, 367 | "metadata": { 368 | "collapsed": true 369 | }, 370 | "outputs": [], 371 | "source": [] 372 | } 373 | ], 374 | "metadata": { 375 | "kernelspec": { 376 | "display_name": "Python 3", 377 | "language": "python", 378 | "name": "python3" 379 | }, 380 | "language_info": { 381 | "codemirror_mode": { 382 | "name": "ipython", 383 | "version": 3 384 | }, 385 | "file_extension": ".py", 386 | "mimetype": "text/x-python", 387 | "name": "python", 388 | "nbconvert_exporter": "python", 389 | "pygments_lexer": "ipython3", 390 | "version": "3.6.0" 391 | } 392 | }, 393 | "nbformat": 4, 394 | "nbformat_minor": 2 395 | } 396 | -------------------------------------------------------------------------------- /Scripts/Pymatgen/ELF.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | import os 3 | import numpy as np 4 | from Element import Element 5 | from ase.calculators.vasp import VaspChargeDensity 6 | metals = ['Ba', 'Be', 'Ca', 'Cs', 'Fr', 'K', 'Li', 'Mg', 'Na', 'Ra', 7 | 'Rb', 'Sr', 'Al', 'Bi', 'Ga', 'In', 'Pb', 'Sn', 'Tl','Ac', 8 | 'Ag', 'Am', 'Au', 'Bk', 'Cd', 'Ce', 'Cf', 'Cm', 'Co', 'Cr', 9 | 'Cu', 'Dy', 'Er', 'Es', 'Eu', 'Fe', 'Fm', 'Gd', 'Hf', 'Hg', 10 | 'Ho', 'Ir', 'La', 'Lr', 'Lu', 'Md', 'Mn', 'Mo', 'Nb', 'Nd', 11 | 'Ni', 'No', 'Np', 'Os', 'Pa', 'Pd', 'Pm', 'Pr', 'Pt', 'Pu', 12 | 'Re', 'Rh', 'Ru', 'Sc', 'Sm', 'Ta', 'Tb', 'Tc', 'Th', 'Ti', 13 | 'Tm', 'U', 'V', 'W', 'Y', 'Yb', 'Zn', 'Zr'] 14 | def get_subdir(a_dir): 15 | return sorted([name for name in os.listdir(a_dir) 16 | if os.path.isdir(os.path.join(a_dir, name))]) 17 | 18 | class elf: 19 | """ 20 | parse electride from a directory containing 21 | ELFCAR, PARCHG and vasprun.xml 22 | """ 23 | 24 | def __init__(self, path = './', 25 | cmd = 'gtimeout -t 30 -T 50 bader ', 26 | ELF_min = 0.20): 27 | 28 | self.error = None 29 | self.ELF_maxima = [] 30 | 31 | ELFCAR_path = path + '/ELFCAR' 32 | clean_cmd1 = 'rm ELFCAR-m bader_log ACF.dat BCF.dat AVF.dat' 33 | 34 | cell, coor, symbols, radii, grid = self.Read_ELFCAR(ELFCAR_path, ELF_min) 35 | os.system(cmd + 'ELFCAR-m > bader_log') 36 | if os.path.exists('BCF.dat') is False: 37 | self.error = 'bader error in parsing ELFCAR' 38 | else: 39 | self.ELF_maxima, self.fac1 = self.Read_BCF('BCF.dat', symbols, radii, cell) 40 | os.system(clean_cmd1) 41 | self.elf_max = self.Read_ELF(ELFCAR_path, self.ELF_maxima) 42 | 43 | @staticmethod 44 | def Read_ELF(filename, poss): 45 | test0 = VaspChargeDensity(filename) 46 | chg = np.array(test0.chg) 47 | grids = np.shape(chg)[1:] 48 | vol = test0.atoms[0].get_volume() 49 | elf_max=[] 50 | step = 2 51 | for pos in poss: 52 | x_min, x_max = int(pos[0]*grids[0])-step, int(pos[0]*grids[0])+step 53 | y_min, y_max = int(pos[1]*grids[1])-step, int(pos[1]*grids[1])+step 54 | z_min, z_max = int(pos[2]*grids[2])-step, int(pos[2]*grids[2])+step 55 | if x_min < 0: x_min=0 56 | if y_min < 0: y_min=0 57 | if z_min < 0: z_min=0 58 | if x_max >= grids[0]: x_max=grids[0]-1 59 | if y_max >= grids[1]: y_max=grids[1]-1 60 | if z_max >= grids[2]: z_max=grids[2]-1 61 | elf_max.append(vol*np.max(chg[0, x_min:x_max, y_min:y_max, z_min:z_max])) 62 | if elf_max: 63 | return max(elf_max) 64 | else: 65 | return 0 66 | 67 | @staticmethod 68 | def Read_BCF(filename, symbols, radii, cell): 69 | f = open(filename, 'rb') 70 | input_content = f.readlines() 71 | f.close() 72 | pos = [] 73 | count = 0 74 | cell = np.linalg.inv(cell) 75 | for i in range(len(input_content)): 76 | s = input_content[i].split() 77 | if s[0].isdigit(): 78 | a=[float(f) for f in s] 79 | if a[-1]>2.0 or ((symbols[int(a[-2])-1] in metals) and (1.2*radii[int(a[-2])-1] < a[-1])): 80 | count += 1 81 | if len(pos) < 4: 82 | pos.append(np.dot(np.array(a[1:4]), cell)) 83 | if len(pos) > 0: 84 | fac = count/len(pos) 85 | else: 86 | fac = 1.0 87 | return np.array(pos), fac 88 | 89 | @staticmethod 90 | def Read_ELFCAR(filename, ELF_min): 91 | """ 92 | This module reads ELFCAR 93 | """ 94 | f = open(filename, 'rb') 95 | f1 = open('ELFCAR-m', 'w') 96 | input_content = f.readlines() 97 | f.close() 98 | count = 0 99 | cell = [] #cell vector 100 | coor = [] 101 | ELF_raw = [] 102 | N_atoms = 0 #how many lines before getting ELF grid 103 | grid = [] 104 | for line in input_content: #[:20]: 105 | line=str(line,'utf-8') 106 | count = count + 1 107 | if count < 3: 108 | f1.write(line) 109 | elif (count>=3) and (count<=5): 110 | cell.append([float(f) for f in line.split()]) 111 | f1.write(line) 112 | elif count==6: 113 | f1.write(line) 114 | symbol = line.split() 115 | elif count==7: 116 | f1.write(line) 117 | numIons = [int(f) for f in line.split()] 118 | N_atoms = sum(numIons) 119 | f1.write('Direct\n') 120 | elif (count>=9) and (count<9+N_atoms): 121 | f1.write(line) 122 | coor.append([float(f) for f in line.split()]) 123 | elif count == 10+N_atoms: 124 | f1.write('\n') 125 | f1.write(line) 126 | grid = [int(f) for f in line.split()] 127 | elif count > 10+N_atoms: 128 | ELF_raw = line.split() 129 | for i, f in enumerate(ELF_raw): 130 | if float(f) 140 or min(struc.lattice.angles) < 40: 81 | struc = finder.get_conventional_standard_structure() 82 | if count < 10: 83 | label = '00'+str(count) 84 | elif count < 100: 85 | label = '0'+str(count) 86 | else: 87 | label = str(count) 88 | 89 | Name = label + '-' + str(struc.formula).replace(" ", "") 90 | print('Creating new directory: ', Name) 91 | if os.path.isdir(Name) is False: 92 | os.mkdir(Name) 93 | os.chdir(Name) 94 | if os.path.exists('static-vasprun.xml') is False: 95 | 96 | myset = {"ISPIN": 1, 97 | "ALGO": 'Normal', 98 | "PREC": 'Normal', 99 | "ENCUT": 400, 100 | "ICHARG": 0, 101 | "LAECHG": "False", 102 | 'NELM': 60, 103 | "LVHAR": "False", 104 | "ISMEAR": 1, 105 | } 106 | 107 | opt = MPRelaxSet(struc, user_incar_settings=myset) 108 | opt.write_input(opt_dir) 109 | run_vasp(cmd, opt_dir) 110 | 111 | if os.stat(opt_dir+'/CONTCAR').st_size == 0: 112 | myset = {"ISPIN": 1, 113 | "ALGO": 'Normal', 114 | "PREC": 'Normal', 115 | "ENCUT": 400, 116 | "ICHARG": 0, 117 | "LAECHG": "False", 118 | 'NELM': 60, 119 | "LVHAR": "False", 120 | "ISMEAR": 1, 121 | "SYMPREC": 1e-8, 122 | } 123 | opt = MPRelaxSet(struc, user_incar_settings=myset) 124 | opt.write_input(opt_dir) 125 | run_vasp(cmd, opt_dir) 126 | 127 | myset = {"ISPIN": 1, 128 | "ALGO": 'Normal', 129 | "LAECHG": "False", 130 | 'NELM': 60, 131 | "LVHAR": "False", 132 | "ISMEAR": 1, 133 | } 134 | 135 | struc = Poscar.from_file(opt_dir+'/CONTCAR').structure 136 | opt = MPRelaxSet(struc, user_incar_settings=myset) 137 | opt.write_input(opt_dir) 138 | run_vasp(cmd, opt_dir) 139 | shutil.rmtree(opt_dir) 140 | 141 | myset = {"ISPIN": 1, 142 | "LAECHG": "False", 143 | "LVHAR": "False", 144 | "LWAVE": "True", 145 | "ISMEAR": 1, 146 | "LELF": "True"} 147 | 148 | static = MPStaticSet(struc, user_incar_settings=myset) 149 | static.write_input(static_dir) 150 | run_vasp(cmd, static_dir) 151 | if os.stat(static_dir+'/CONTCAR').st_size == 0: 152 | myset = {"ISPIN": 1, 153 | "LAECHG": "False", 154 | 'NELM': 60, 155 | "LVHAR": "False", 156 | # "LWAVE": "True", 157 | "ISMEAR": 1, 158 | "SYMPREC": 1e-8, 159 | # "LELF": "True", 160 | } 161 | static = MPStaticSet(struc, user_incar_settings=myset) 162 | static.write_input(static_dir) 163 | run_vasp(cmd, static_dir) 164 | 165 | os.system('cp ' + static_dir + '/vasprun.xml ./static-vasprun.xml') 166 | 167 | # 2nd run to obtain dos 168 | dos = MPNonSCFSet.from_prev_calc(static_dir, 169 | mode="uniform", 170 | reciprocal_density=200, 171 | user_incar_settings=myset) 172 | dos.write_input(dos_dir) 173 | run_vasp(cmd, dos_dir) 174 | os.system('cp ' + dos_dir + '/vasprun.xml ./dos-vasprun.xml') 175 | 176 | # 3rd run to obtain Band structure 177 | band = MPNonSCFSet.from_prev_calc(static_dir, 178 | mode="line", 179 | standardize=True, 180 | user_incar_settings=myset) 181 | band.write_input(band_dir) 182 | run_vasp(cmd, band_dir) 183 | os.system('cp ' + band_dir + '/vasprun.xml ./band-vasprun.xml') 184 | os.system('cp ' + band_dir + '/KPOINTS ./') 185 | 186 | v = BSVasprun("band-vasprun.xml") 187 | bs = v.get_band_structure(kpoints_filename='KPOINTS', line_mode=True) 188 | plt = BSPlotter(bs) 189 | plt.get_plot(vbm_cbm_marker=True) 190 | plt.save_plot(Name+'-band.png', ylim=[-4, 4], img_format='png') 191 | 192 | v = Vasprun('dos-vasprun.xml') 193 | tdos = v.tdos 194 | cdos = v.complete_dos 195 | spd_dos = cdos.get_spd_dos() 196 | plotter = DosPlotter(sigma=0.1) 197 | plotter.add_dos("Total DOS", tdos) 198 | # plotter.add_dos("spd_dos", spd_dos) 199 | plotter.save_plot(Name+'-dos.png', img_format='png', xlim=[-4, 4]) 200 | 201 | shutil.rmtree(band_dir) 202 | shutil.rmtree(dos_dir) 203 | shutil.rmtree(static_dir) 204 | 205 | os.chdir('../') 206 | -------------------------------------------------------------------------------- /Scripts/Pymatgen/bcc-sub.py: -------------------------------------------------------------------------------- 1 | """ 2 | Create an ase db file to store the information from the Sci. Rep. paper 3 | """ 4 | import os 5 | import warnings 6 | warnings.filterwarnings("ignore") 7 | 8 | from pymatgen.ext.matproj import MPRester 9 | from pyxtal import pyxtal 10 | 11 | def process(pmg, id, spg, composition, comp): 12 | """ 13 | check if this is a new structure 14 | 15 | Args: 16 | pmg: input structure 17 | refs: list of reference structures 18 | 19 | """ 20 | s1 = pyxtal() 21 | try: 22 | s1.from_seed(pmg, tol=1e-3) 23 | except: 24 | print("wrong", pmg) 25 | if s1.group.number == 229 and len(s1.atom_sites)==1 and s1.atom_sites[0].wp.multiplicity==2: 26 | strs = '{:20s} {:3d} {:12s} {:6.2f}'.format(id, spg, composition.to_pretty_string(), comp) 27 | if comp > 0.45: 28 | strs += '+++++++' 29 | print(strs) 30 | print(s1.atom_sites) 31 | 32 | 33 | mpr = MPRester('fn8WQGgT9rvZAh6H') # insert your keys here 34 | 35 | #define your search criteria 36 | criteria ={#"band_gap": {"$gt":0.1}, 37 | "spacegroup.number": {"$gt": 75}, 38 | "nelements": {"$in": [2, 3]}, 39 | "nsites": {"$lt": 60}, 40 | } 41 | 42 | #choose the properties which you are interested: 43 | properties = [ 44 | "material_id", 45 | "band_gap", 46 | "e_above_hull", 47 | "structure", 48 | "spacegroup.number", 49 | "composition_reduced", 50 | #"cif", 51 | ] 52 | entries = mpr.query(criteria=criteria, properties=properties) 53 | print("=============================Initial:", len(entries)) 54 | 55 | 56 | for i, entry in enumerate(entries): 57 | pmg = entry['structure'] 58 | eles = [ele.symbol for ele in pmg.composition.elements] 59 | for ele in eles: 60 | pmg0 = pmg.copy() 61 | todo = [e0 for e0 in eles if e0 != ele] 62 | pmg0.remove_species(todo) 63 | comp = pmg.composition.fractional_composition.get_atomic_fraction(ele) 64 | process(pmg0, entry['material_id'], entry['spacegroup.number'], pmg.composition, comp) 65 | -------------------------------------------------------------------------------- /Scripts/Pymatgen/check_Stability.py: -------------------------------------------------------------------------------- 1 | from pymatgen.core.periodic_table import Element 2 | from optparse import OptionParser 3 | from pymatgen.io.vasp.outputs import Vasprun 4 | from vasprun import vasprun 5 | from pymatgen.entries.compatibility import MaterialsProjectCompatibility 6 | from pymatgen.symmetry.analyzer import SpacegroupAnalyzer 7 | from pymatgen import MPRester 8 | from pymatgen.analysis.phase_diagram import PhaseDiagram 9 | import os 10 | import pandas as pd 11 | from tabulate import tabulate 12 | import collections 13 | 14 | def first_2chars(x): 15 | return(x[:3]) 16 | def get_subdir(a_dir): 17 | return sorted([name for name in os.listdir(a_dir) 18 | if os.path.isdir(os.path.join(a_dir, name))]) 19 | def get_symbol(elements): 20 | symbol=[] 21 | for i in my_entry.composition.elements: 22 | symbol.append(i.symbol) 23 | return symbol 24 | #------------------------------------------------------------------- 25 | parser = OptionParser() 26 | parser.add_option("-d", "--dir", dest='dir', default='.', 27 | help="by directory") 28 | (options, args) = parser.parse_args() 29 | 30 | pd.set_option('precision', 3) 31 | output = collections.OrderedDict( 32 | {'formula': [], 33 | 'Space group': [], 34 | 'E_formation': [], 35 | 'E_above_hull': [], 36 | }) 37 | 38 | filename = 'static-vasprun.xml' 39 | csvname = 'stability.csv' 40 | #------------------------------------------------------------------- 41 | if os.path.exists(csvname): 42 | output0 = pd.read_csv(csvname) 43 | output = collections.OrderedDict( 44 | {'formula': output0.formula.values.tolist(), 45 | 'Space_group': output0.Space_group.values.tolist(), 46 | 'E_formation': output0.E_formation.values.tolist(), 47 | 'E_above_hull': output0.E_above_hull.values.tolist(), 48 | 'Dir': output0.Dir.values.tolist(), 49 | }) 50 | 51 | else: 52 | output = collections.OrderedDict( 53 | {'formula': [], 54 | 'Space_group': [], 55 | 'E_formation': [], 56 | 'E_above_hull': [], 57 | 'Dir': [], 58 | }) 59 | 60 | mpr = MPRester('fn8WQGgT9rvZAh6H') 61 | compat = MaterialsProjectCompatibility() # sets energy corrections and +U/pseudopotential choice 62 | dirs = get_subdir(options.dir) 63 | os.chdir(options.dir) 64 | fname = '' 65 | for dir in dirs: 66 | path = dir+'/'+filename 67 | if dir not in output['Dir']: 68 | try: 69 | if vasprun(path).error: 70 | print('vasp calculation is not converged') 71 | else: 72 | vaspcal = Vasprun(path) 73 | my_entry = vaspcal.get_computed_entry(inc_structure=True) 74 | struc = my_entry.structure 75 | spg = SpacegroupAnalyzer(struc,symprec=0.01).get_space_group_symbol() 76 | symbol = get_symbol(my_entry.composition.elements) 77 | entries = mpr.get_entries_in_chemsys(symbol) 78 | entries = compat.process_entries(entries) 79 | N_exist = len(entries) 80 | corrections_dict = compat.get_corrections_dict(my_entry) 81 | if len(corrections_dict) > 0: 82 | pretty_corrections = ["{}:{}".format(k, round(v, 3)) for k, v in corrections_dict.items()] 83 | print("We are applying the following corrections (eV) to the user entry: {}".format(pretty_corrections)) 84 | 85 | my_entry.correction = sum(corrections_dict.values()) 86 | entries.append(my_entry) 87 | tmp = [] 88 | for ele in symbol: 89 | tmp.append(Element(ele)) 90 | pda = PhaseDiagram(entries, elements=tmp) 91 | 92 | e_above_hull = pda.get_e_above_hull(entries[-1]) 93 | e_form = pda.get_form_energy_per_atom(entries[-1]) 94 | output['E_above_hull'].append(e_above_hull) 95 | output['E_formation'].append(e_form) 96 | output['formula'].append(struc.composition.get_reduced_formula_and_factor()[0]) 97 | output['Space group'].append(spg) 98 | output['Dir'].append(dir) 99 | except: 100 | print('vasp error in ', dir) 101 | 102 | 103 | df = pd.DataFrame(output) 104 | df = df.sort_values(['E_above_hull', 'E_formation', 'formula'], 105 | ascending=[True, True, True]) 106 | print(tabulate(df, headers='keys', tablefmt='psql')) 107 | df.to_csv(csvname) 108 | print(len(df), ' structures have been processed') 109 | -------------------------------------------------------------------------------- /Scripts/Pymatgen/cif2POSCAR.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # encoding: utf-8 3 | 4 | ''' 5 | $Author: Qiang Zhu $ 6 | Export cif file from POSCAR 7 | ''' 8 | 9 | 10 | from optparse import OptionParser 11 | import pymatgen as mg 12 | from pymatgen.io.cif import CifWriter 13 | 14 | # ------------------------------------------------------------------ 15 | # -------------------------------- Options ------------------------- 16 | parser = OptionParser() 17 | parser.add_option('-i', '--input', help='input POSCAR file') 18 | parser.add_option('-o', '--output', help='output cif file') 19 | 20 | (options, args) = parser.parse_args() 21 | structure = mg.Structure.from_file(options.input) 22 | structure.to(filename=options.output) 23 | -------------------------------------------------------------------------------- /Scripts/Pymatgen/download_json.py: -------------------------------------------------------------------------------- 1 | import json 2 | from pymatgen import MPRester 3 | 4 | mpr = MPRester('fn8WQGgT9rvZAh6H') 5 | bs=mpr.get_bandstructure_by_material_id('mp-3315').as_dict() #,line_mode=True) 6 | with open("test.json", "w") as outfile: 7 | json.dump(bs, outfile, indent=4) 8 | -------------------------------------------------------------------------------- /Scripts/Pymatgen/search.py: -------------------------------------------------------------------------------- 1 | from pymatgen import MPRester 2 | from pymatgen.core.periodic_table import Element 3 | from pymatgen.symmetry.analyzer import SpacegroupAnalyzer 4 | from pymatgen.analysis.phase_diagram import PhaseDiagram 5 | import os 6 | import warnings 7 | from optparse import OptionParser 8 | from pymatgen.io.cif import CifWriter 9 | 10 | warnings.filterwarnings("ignore") 11 | 12 | 13 | def parse_system(input): 14 | if input.find('-') > 0: 15 | return input.split('-') 16 | else: 17 | return input 18 | 19 | 20 | def output_struc(entry, eng, tol): 21 | id = entry.entry_id 22 | todo = mpr.get_structure_by_material_id(id) 23 | finder = SpacegroupAnalyzer(todo, symprec=tol, angle_tolerance=5) 24 | newStruc = finder.get_refined_structure() 25 | if len(newStruc.frac_coords) > 16: 26 | newStruc = newStruc.get_primitive_structure() 27 | p1 = ['{:6.3f}'.format(j) for j in newStruc.lattice.abc] 28 | p2 = ['{:6.2f}'.format(j) for j in newStruc.lattice.angles] 29 | sym = finder.get_space_group_symbol() 30 | s = ' '.join(map(str, p1+p2)) 31 | print('%-16s %40s %6.3f %10s [%s]' % (id, s, eng, sym, newStruc.formula)) 32 | return newStruc 33 | 34 | 35 | if __name__ == "__main__": 36 | # ------------------------------------------------------------------ 37 | # -------------------------------- Options ------------------------- 38 | parser = OptionParser() 39 | parser.add_option("-c", "--cut", dest="cutoff", metavar='cutoff', 40 | type='float', default=0, 41 | help="cutoff energy for e_above_hull") 42 | 43 | parser.add_option("-d", "--dim", dest="dimension", type='int', 44 | help="export all dimensions", metavar="dimension") 45 | 46 | parser.add_option("-e", "--element", dest="element", type='string', 47 | help="chemical system", metavar="element") 48 | 49 | parser.add_option("-i", "--id", dest="id", metavar="id", 50 | help="materials id") 51 | 52 | parser.add_option("-f", "--format", dest="format", default='poscar', 53 | help="export structure in which format, poscar or cif", 54 | metavar="format") 55 | 56 | (options, args) = parser.parse_args() 57 | 58 | mpr = MPRester('9RTlN5ZOXst6PAdS') 59 | strucs = [] 60 | if options.id is None: 61 | system = parse_system(options.element) 62 | if type(system) is not list: 63 | mp_entries = mpr.get_entries(system) 64 | else: 65 | mp_entries = mpr.get_entries_in_chemsys(system) 66 | pd = PhaseDiagram(mp_entries) 67 | if options.dimension is None: 68 | options.dimension = len(system) 69 | for entry in mp_entries: 70 | accept = False 71 | if type(system) is list: 72 | if len(entry.composition) >= options.dimension: 73 | eng = pd.get_e_above_hull(entry) 74 | if eng <= options.cutoff: 75 | accept = True 76 | else: 77 | eng = entry.energy_per_atom 78 | accept = True 79 | if accept: 80 | struc = output_struc(entry, eng, tol=1e-2) 81 | strucs.append(struc) 82 | else: 83 | strucs.append(mpr.get_structure_by_material_id(options.id)) 84 | 85 | if options.format == 'poscar': 86 | filename = 'MPR.vasp' 87 | else: 88 | filename = 'MPR.cif' 89 | 90 | if os.path.isfile(filename): 91 | os.remove(filename) 92 | 93 | for struc in strucs: 94 | if options.format == 'poscar': 95 | content = struc.to(fmt='poscar') 96 | else: 97 | content = str(CifWriter(struc, symprec=0.01)) 98 | with open(filename, 'a+') as f: 99 | f.writelines(content) 100 | -------------------------------------------------------------------------------- /Scripts/Pymatgen/search_dimer.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": { 6 | "collapsed": true 7 | }, 8 | "source": [ 9 | "# Find the dimer\n", 10 | "This is a simple example to illustrate how to search for the structures containing C-C or N-N dimers from [Materials Project](http://materialsproject.org)\n", 11 | "\n", 12 | "**Tip**: this is just a toy example to illustrate the functionality. If you want to use it for production. Better run it with pure \\*.py script.\n", 13 | "\n", 14 | "**Copyright**: qiang.zhu@unlv.edu\n", 15 | "**Date Created**: 2018/08/13" 16 | ] 17 | }, 18 | { 19 | "cell_type": "code", 20 | "execution_count": 1, 21 | "metadata": {}, 22 | "outputs": [], 23 | "source": [ 24 | "from pymatgen import MPRester\n", 25 | "\n", 26 | "mpr = MPRester('fn8WQGgT9rvZAh6H') # insert your keys here\n", 27 | "\n", 28 | "#define your search criteria\n", 29 | "#more info can be found at https://materialsproject.org/docs/api\n", 30 | "\n", 31 | "criteria ={\"band_gap\": {\"$gt\":1.0},\n", 32 | " \"e_above_hull\": {\"$lt\":0.01},\n", 33 | " #\"spacegroup.crystal_system\": \"hexagonal\",\n", 34 | " \"elements\": {\"$all\": [\"N\"]},\n", 35 | " \"nelements\":{\"$lt\":3}, \n", 36 | " #\"pretty_formula\": \"BaTiO3\",\n", 37 | " }\n", 38 | "\n", 39 | "#choose the properties which you are interested:\n", 40 | "\n", 41 | "properties = [\"pretty_formula\", \n", 42 | " \"material_id\", \n", 43 | " \"spacegroup.symbol\", \n", 44 | " \"e_above_hull\",\n", 45 | " \"structure\",\n", 46 | " ]\n", 47 | "entries = mpr.query(criteria=criteria, properties=properties)" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 2, 53 | "metadata": {}, 54 | "outputs": [ 55 | { 56 | "data": { 57 | "text/plain": [ 58 | "49" 59 | ] 60 | }, 61 | "execution_count": 2, 62 | "metadata": {}, 63 | "output_type": "execute_result" 64 | } 65 | ], 66 | "source": [ 67 | "# output the number of entries which satisfy the above criteria\n", 68 | "len(entries)" 69 | ] 70 | }, 71 | { 72 | "cell_type": "code", 73 | "execution_count": 3, 74 | "metadata": { 75 | "collapsed": true 76 | }, 77 | "outputs": [], 78 | "source": [ 79 | "# a simple function to find the C-C dimers\n", 80 | "def compute_dimer(struc, specie='C', dist=1.6):\n", 81 | "\n", 82 | " for site in struc.sites:\n", 83 | " if site.species_string==specie:\n", 84 | " a = struc.get_neighbors(site, r=dist)\n", 85 | " if len(a)==1 and a[0][0].species_string==specie:\n", 86 | " return True\n", 87 | " return False" 88 | ] 89 | }, 90 | { 91 | "cell_type": "code", 92 | "execution_count": 4, 93 | "metadata": { 94 | "scrolled": false 95 | }, 96 | "outputs": [], 97 | "source": [ 98 | "from pymatgen.symmetry.analyzer import SpacegroupAnalyzer\n", 99 | "import pandas as pd\n", 100 | "\n", 101 | "formula = []\n", 102 | "e_above_hull = []\n", 103 | "spg = []\n", 104 | "mid = []\n", 105 | "\n", 106 | "for entry in entries:\n", 107 | " struc=entry['structure']\n", 108 | " finder = SpacegroupAnalyzer(struc,symprec=0.06,angle_tolerance=5)\n", 109 | " struc = finder.get_conventional_standard_structure()\n", 110 | " if compute_dimer(struc, specie='N'):\n", 111 | " formula.append(entry['pretty_formula'])\n", 112 | " spg.append(entry['spacegroup.symbol'])\n", 113 | " e_above_hull.append(entry['e_above_hull'])\n", 114 | " mid.append(entry['material_id'])\n", 115 | " \n", 116 | "col_name = {'Formula': formula,\n", 117 | " 'Space group': spg,\n", 118 | " 'e_above_hull': e_above_hull,\n", 119 | " 'material_id': mid,\n", 120 | " }\n", 121 | "df = pd.DataFrame(col_name)\n", 122 | "df = df.sort_values(['e_above_hull', 'Space group'], ascending=[True, False])" 123 | ] 124 | }, 125 | { 126 | "cell_type": "code", 127 | "execution_count": 5, 128 | "metadata": {}, 129 | "outputs": [ 130 | { 131 | "data": { 132 | "text/html": [ 133 | "
\n", 134 | "\n", 147 | "\n", 148 | " \n", 149 | " \n", 150 | " \n", 151 | " \n", 152 | " \n", 153 | " \n", 154 | " \n", 155 | " \n", 156 | " \n", 157 | " \n", 158 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | " \n", 190 | " \n", 191 | " \n", 192 | " \n", 193 | " \n", 194 | " \n", 195 | " \n", 196 | " \n", 197 | " \n", 198 | " \n", 199 | " \n", 200 | " \n", 201 | " \n", 202 | " \n", 203 | " \n", 204 | " \n", 205 | " \n", 206 | " \n", 207 | " \n", 208 | " \n", 209 | " \n", 210 | " \n", 211 | " \n", 212 | " \n", 213 | " \n", 214 | " \n", 215 | " \n", 216 | " \n", 217 | " \n", 218 | " \n", 219 | " \n", 220 | " \n", 221 | " \n", 222 | " \n", 223 | " \n", 224 | " \n", 225 | " \n", 226 | " \n", 227 | " \n", 228 | " \n", 229 | " \n", 230 | " \n", 231 | " \n", 232 | " \n", 233 | " \n", 234 | " \n", 235 | " \n", 236 | " \n", 237 | " \n", 238 | " \n", 239 | " \n", 240 | " \n", 241 | " \n", 242 | " \n", 243 | " \n", 244 | " \n", 245 | " \n", 246 | " \n", 247 | " \n", 248 | " \n", 249 | " \n", 250 | " \n", 251 | " \n", 252 | " \n", 253 | " \n", 254 | " \n", 255 | " \n", 256 | " \n", 257 | " \n", 258 | " \n", 259 | " \n", 260 | " \n", 261 | " \n", 262 | " \n", 263 | " \n", 264 | " \n", 265 | " \n", 266 | " \n", 267 | " \n", 268 | " \n", 269 | " \n", 270 | " \n", 271 | " \n", 272 | " \n", 273 | " \n", 274 | " \n", 275 | " \n", 276 | " \n", 277 | " \n", 278 | " \n", 279 | " \n", 280 | " \n", 281 | " \n", 282 | " \n", 283 | " \n", 284 | " \n", 285 | "
FormulaSpace groupe_above_hullmaterial_id
12BaN6P2_1/m0.000000e+00mp-1707
10WN2P-6m20.000000e+00mp-999549
8CsN3I4/mcm0.000000e+00mp-510557
16RbN3I4/mcm0.000000e+00mp-743
17KN3I4/mcm0.000000e+00mp-827
5CaN6Fddd0.000000e+00mp-676
14SrN6Fddd0.000000e+00mp-2131
11NaN3Cm0.000000e+00mp-1064952
13LiN3C2/m0.000000e+00mp-2659
2N2R-3c8.881784e-16mp-568584
0N2Pa-38.881784e-16mp-25
4N2P6_3/mmc8.881784e-16mp-672233
3N2P4_2/mnm8.881784e-16mp-570747
1N2P2_138.881784e-16mp-154
15WN2P6_3/mmc2.937433e-04mp-1077232
6NaN3R-3m7.059425e-04mp-22003
7NaN3C2/m7.522150e-04mp-570538
9NaN3R3m2.595515e-03mp-1066400
\n", 286 | "
" 287 | ], 288 | "text/plain": [ 289 | " Formula Space group e_above_hull material_id\n", 290 | "12 BaN6 P2_1/m 0.000000e+00 mp-1707\n", 291 | "10 WN2 P-6m2 0.000000e+00 mp-999549\n", 292 | "8 CsN3 I4/mcm 0.000000e+00 mp-510557\n", 293 | "16 RbN3 I4/mcm 0.000000e+00 mp-743\n", 294 | "17 KN3 I4/mcm 0.000000e+00 mp-827\n", 295 | "5 CaN6 Fddd 0.000000e+00 mp-676\n", 296 | "14 SrN6 Fddd 0.000000e+00 mp-2131\n", 297 | "11 NaN3 Cm 0.000000e+00 mp-1064952\n", 298 | "13 LiN3 C2/m 0.000000e+00 mp-2659\n", 299 | "2 N2 R-3c 8.881784e-16 mp-568584\n", 300 | "0 N2 Pa-3 8.881784e-16 mp-25\n", 301 | "4 N2 P6_3/mmc 8.881784e-16 mp-672233\n", 302 | "3 N2 P4_2/mnm 8.881784e-16 mp-570747\n", 303 | "1 N2 P2_13 8.881784e-16 mp-154\n", 304 | "15 WN2 P6_3/mmc 2.937433e-04 mp-1077232\n", 305 | "6 NaN3 R-3m 7.059425e-04 mp-22003\n", 306 | "7 NaN3 C2/m 7.522150e-04 mp-570538\n", 307 | "9 NaN3 R3m 2.595515e-03 mp-1066400" 308 | ] 309 | }, 310 | "execution_count": 5, 311 | "metadata": {}, 312 | "output_type": "execute_result" 313 | } 314 | ], 315 | "source": [ 316 | "df" 317 | ] 318 | }, 319 | { 320 | "cell_type": "code", 321 | "execution_count": null, 322 | "metadata": { 323 | "collapsed": true 324 | }, 325 | "outputs": [], 326 | "source": [] 327 | } 328 | ], 329 | "metadata": { 330 | "kernelspec": { 331 | "display_name": "Python 3", 332 | "language": "python", 333 | "name": "python3" 334 | }, 335 | "language_info": { 336 | "codemirror_mode": { 337 | "name": "ipython", 338 | "version": 3 339 | }, 340 | "file_extension": ".py", 341 | "mimetype": "text/x-python", 342 | "name": "python", 343 | "nbconvert_exporter": "python", 344 | "pygments_lexer": "ipython3", 345 | "version": "3.6.0" 346 | } 347 | }, 348 | "nbformat": 4, 349 | "nbformat_minor": 2 350 | } 351 | -------------------------------------------------------------------------------- /Scripts/Pymatgen/work/Gap_screen-1.csv: -------------------------------------------------------------------------------- 1 | ,Formula,Space group,Material_id,Gap,e_above_hull,N_sites,Density 2 | 5,Si,P6_3/mmc,mp-165,0.45169999999999977,0.010745889999999925,4,2.281615852593324 3 | 4,Si,Fd-3m,mp-149,0.6118999999999994,0.0,2,2.2811943005642012 4 | 2,P,Cmce,mp-157,0.6744000000000003,0.03002964690476162,4,2.4363409033735235 5 | 3,Se,P3_121,mp-14,0.9987999999999999,0.005984748072916712,3,4.403367279205449 6 | 1,I,Cmce,mp-23153,1.0140999999999998,0.0,4,4.07468463929697 7 | 0,Hg,P2_1/c,mp-1077098,1.0986,0.020464718333333298,6,8.858266193384662 8 | -------------------------------------------------------------------------------- /Scripts/Pymatgen/work/Gap_screen-2.csv: -------------------------------------------------------------------------------- 1 | ,Formula,Space group,Material_id,Gap,e_above_hull,N_sites,Density 2 | 15,Si3As4,P-43m,mp-570744,0.4043000000000001,0.07167499827380919,7,4.117948364663989 3 | 153,Na3P,P6_3/mmc,mp-1598,0.40460000000000007,0.0,8,1.7517808309719398 4 | 158,SnO,P4/nmm,mp-2097,0.4096000000000002,0.0,4,5.942456569873526 5 | 35,CuBr,P6_3/mmc,mp-23227,0.42989999999999995,0.04142656500000008,4,4.865375526057564 6 | 185,PbSe,Fm-3m,mp-2201,0.43100000000000005,0.0,2,7.886313734551845 7 | 96,FeP2,Pnnm,mp-20027,0.4338999999999995,0.0,6,5.1277139640003515 8 | 139,MgTe,Fm-3m,mp-1008786,0.43430000000000035,0.0639015624999999,2,4.720270558500913 9 | 16,Te3As2,C2/m,mp-484,0.4366999999999992,0.0,10,5.7422069205567965 10 | 121,InS,P2_1/c,mp-630528,0.4394,0.028054021250000005,8,5.18250982233848 11 | 4,AgCl,Cmcm,mp-570858,0.44379999999999975,0.03589157999999992,4,5.535540006067872 12 | 209,Tl2Te3,Cc,mp-680731,0.44479999999999986,0.024404259999999844,10,7.1198993596065305 13 | 10,Cs2As3,Fmmm,mp-15557,0.4474999999999998,0.0,10,3.863184144736802 14 | 13,As2Ru,Pnnm,mp-766,0.44920000000000027,0.0,6,8.051427197454801 15 | 77,Cr2S3,R3,mp-849081,0.4563999999999995,0.0,10,3.957811929612679 16 | 125,InSe,P6_3/mmc,mp-1079454,0.4575,0.0048767237499989236,8,5.024550283292372 17 | 123,InSe,P6_3/mmc,mp-20485,0.4575,0.0013706312499999207,8,5.078137367167329 18 | 176,P2Pd,C2/c,mp-28266,0.4579000000000004,0.0,6,5.431193337368535 19 | 148,SmN,Fm-3m,mp-749,0.45950000000000024,0.0,2,8.3562752623617 20 | 180,PbS,Fm-3m,mp-21276,0.46720000000000006,0.0,2,7.333906866198274 21 | 119,InP,F-43m,mp-20351,0.4679000000000002,0.0,2,4.581623553814487 22 | 109,MgHg,Pm-3m,mp-1408,0.46940000000000026,0.0,2,8.713422390812287 23 | 178,P2Ru,Pnnm,mp-1413,0.47499999999999964,0.0,6,6.11752675618414 24 | 169,V2O3,R-3c,mp-562005,0.47609999999999975,0.013038598250002309,10,4.635328272050261 25 | 112,HgTe,P3_121,mp-358,0.47619999999999996,0.06284489333333343,6,8.153570171395419 26 | 32,CrBr2,C2/m,mp-567624,0.47919999999999985,0.07185420037036927,3,3.989367148007784 27 | 154,NaSe,P6_3/mmc,mp-15668,0.4799,0.0,8,3.245401308232714 28 | 136,Li3Sb,P6_3/mmc,mp-7955,0.4833000000000003,0.0033612725000002897,8,2.9779825060008456 29 | 33,CuBr,F-43m,mp-22913,0.4859,0.0,2,5.147663767233691 30 | 143,MnP4,P-1,mp-487,0.49239999999999995,0.000343519333334541,10,4.0571320245520015 31 | 86,Cu2O,Pn-3m,mp-361,0.4996999999999998,0.0,6,6.028166000942374 32 | 60,NaCl7,Pm-3,mp-1080771,0.5030000000000001,0.0,8,1.9421576531854452 33 | 76,CrI2,Cmc2_1,mp-567687,0.5076,0.009816106666666435,6,4.361269446865612 34 | 63,OsCl4,Cmmm,mp-571035,0.5104999999999998,0.0,5,4.000113850071358 35 | 175,SiOs,P2_13,mp-2488,0.5122,0.01194814333333305,8,13.160494722286373 36 | 120,InP,P6_3mc,mp-966800,0.5146000000000006,0.005902545000000536,4,4.569158634651977 37 | 202,SnSe,Pnma,mp-691,0.5159000000000002,0.0,8,5.8340206597860185 38 | 164,Tl2O,C2/m,mp-551470,0.5194000000000001,0.0,6,9.508463267992948 39 | 93,RuF4,P2_1/c,mp-974434,0.5254,0.0,10,4.346980494936585 40 | 31,Bi2Te3,R-3m,mp-34202,0.5335999999999999,0.0,5,7.4688150348399365 41 | 161,SnO,Cmce,mp-545820,0.5353999999999992,0.000990455000001056,8,5.840916440413781 42 | 36,FeBr2,P-3m1,mp-22880,0.5376999999999998,0.0,3,4.536917827930927 43 | 168,V2O3,R-3c,mp-18937,0.5414000000000003,0.011643768250001685,10,4.633189600740082 44 | 140,MnO,Fm-3m,mp-19006,0.5425000000000004,0.0,2,5.092191024139196 45 | 30,Bi2Se3,R-3m,mp-541837,0.5434000000000001,0.0,5,7.056071162846153 46 | 127,LuIr,Pm-3m,mp-1529,0.5435999999999996,0.0,2,16.135681569955054 47 | 155,NiP2,C2/c,mp-486,0.5442,0.011164856666667333,6,4.476788338167118 48 | 141,MnO,Fm-3m,mp-578625,0.5502000000000002,0.033150659999998666,2,5.119083880430085 49 | 108,HfSe2,P-3m1,mp-985831,0.5535999999999999,0.0,3,6.538054923123724 50 | 49,Ca2Si,Fm-3m,mp-1009733,0.5549,0.014353125833332925,3,1.951459079706108 51 | 181,PbS,R3m,mp-1057015,0.5555000000000003,0.0008345649999998983,2,7.308180715145071 52 | 103,GeS,Cmcm,mp-12910,0.5581,0.044639061249999834,4,4.110012425694508 53 | 54,CdSe,P6_3mc,mp-1070,0.56,0.001059184999999907,4,5.301027404742621 54 | 59,CuCl,F-43m,mp-22914,0.5611999999999999,0.0,2,4.165254784622299 55 | 23,BaP3,C2/m,mp-7808,0.5735000000000001,0.0,8,3.767180607493873 56 | 44,Ca2Ge,Fm-3m,mp-1009755,0.5756000000000001,0.017027871666667416,3,2.697254598114631 57 | 84,CuH,P6_3mc,mp-24093,0.5783999999999994,0.06154782819000015,4,6.673768880717793 58 | 55,CdTe,F-43m,mp-406,0.5846000000000002,0.0,2,5.472510161471287 59 | 156,PtO2,Pnnm,mp-1285,0.5864000000000003,0.0,6,11.249715034217436 60 | 37,LaBr2,P6_3/mmc,mp-28572,0.5867999999999998,0.003959044333332606,6,4.351826013068257 61 | 142,MnO2,Pnnm,mp-715432,0.5872000000000002,0.03656852416666645,6,4.961733963650254 62 | 48,CaSi2,R-3m,mp-2700,0.5903,0.0015728049999985672,3,2.36214843350885 63 | 9,CdAs2,I4_122,mp-471,0.5958999999999999,0.0,6,5.491634181162118 64 | 106,GeTe,R3m,mp-938,0.5965000000000007,0.0,2,5.909651479586358 65 | 24,BaSe2,C2/c,mp-7547,0.5995000000000001,0.0,6,4.755527176307544 66 | 152,NaO3,Imm2,mp-22464,0.6024,0.07888201843749876,4,2.1173599686864137 67 | 19,EuB6,Pm-3m,mp-20874,0.6101000000000001,0.0,7,5.0132124133983655 68 | 80,Cs3Sb,Fm-3m,mp-10378,0.6137000000000001,0.0,4,4.228331707724108 69 | 78,Cs2O,R-3m,mp-7988,0.6137999999999999,0.0,3,4.047969271736823 70 | 157,Rh2O3,R-3c,mp-542734,0.6193,0.02923587549999951,10,7.634370449830265 71 | 56,CdTe,P6_3mc,mp-12779,0.6198000000000001,0.004014724999999775,4,5.466196012107089 72 | 87,ErN,Fm-3m,mp-19830,0.6297999999999999,0.0,2,10.5658294733128 73 | 172,ZnO,F-43m,mp-1986,0.6310999999999999,0.006964027499999581,2,5.446383569569964 74 | 130,K2Se3,Cmc2_1,mp-7670,0.6329999999999999,0.0,10,3.268849603651539 75 | 11,Li3As,P6_3/mmc,mp-757,0.6364999999999998,0.0,8,2.454983960701101 76 | 83,Cs2Te3,Cmc2_1,mp-505634,0.6368999999999998,0.0,10,4.5264857968592045 77 | 14,As2Se3,C2/m,mp-1078443,0.6385999999999998,0.0,10,5.001775815720731 78 | 43,CaGe2,R-3m,mp-567456,0.6408000000000005,0.0,3,4.1968641795841855 79 | 122,In2S3,R-3c,mp-22375,0.6438999999999995,0.029880469750000138,10,4.712893473291113 80 | 47,Ca2Pb,Fm-3m,mp-1009756,0.6495000000000002,0.03883787166666686,3,4.282124488817178 81 | 160,SnO2,P4_2/mnm,mp-1071822,0.6519000000000004,5.806999999968809e-05,6,6.604471276562272 82 | 159,SnO2,P4_2/mnm,mp-856,0.6519000000000004,0.0,6,6.6088674336338125 83 | 12,As2Os,Pnnm,mp-2455,0.6546000000000003,0.0,6,10.788087720853568 84 | 124,InSe,P-6m2,mp-1079260,0.6587000000000001,0.004774995000000004,8,4.826716753335339 85 | 94,SrF3,P2_1/m,mp-1080514,0.6608,0.0,8,4.032836571428967 86 | 131,KTe,P6_3/mmc,mp-2072,0.6627000000000001,0.0,8,3.207599495136333 87 | 50,Ca2Sn,Fm-3m,mp-1009730,0.6639999999999997,0.03183334583333286,3,3.043352109832327 88 | 99,Ga2Os,Fddd,mp-570875,0.6661000000000001,0.07140113499999323,6,12.47511160619666 89 | 90,PdF4,Fdd2,mp-13868,0.6701999999999999,0.0,10,4.473437928890828 90 | 193,Rb2Se3,Cmc2_1,mp-7447,0.6706000000000001,0.0,10,3.7774983025368565 91 | 174,P4Os,P2_1/c,mp-1087509,0.6758000000000006,0.0,10,6.647137503907119 92 | 129,K3Sb,Fm-3m,mp-10159,0.6773,0.028535317500000268,4,2.5286433394421812 93 | 183,PbS,P6_3mc,mp-1012435,0.6898999999999997,0.056755717500000635,4,6.973010159366624 94 | 149,UN2,Fm-3m,mp-1776,0.6911000000000005,0.0,3,12.015513001416792 95 | 95,UF5,I4/m,mp-1852,0.6921999999999999,0.0,6,5.151624436156307 96 | 134,Li3P,P6_3/mmc,mp-736,0.6996000000000002,0.0,8,1.4622818703719636 97 | 165,Tl2O,R-3m,mp-27484,0.6999,0.0002373466666742985,6,9.413252504477484 98 | 1,AgBr,P2_1/m,mp-570301,0.7,0.04135214750000005,4,6.245163568251635 99 | 151,YN,P6_3/mmc,mp-6913,0.7004999999999999,0.08809957000000068,4,4.905118486495065 100 | 201,SnSe2,P-3m1,mp-665,0.7018,0.0,3,5.120499523397654 101 | 58,CrCl2,Pnnm,mp-655234,0.7019000000000002,0.06391669648148213,6,2.845325327739865 102 | 203,SnSe,Cmcm,mp-2168,0.7042999999999999,0.011448297500000315,4,5.924580591758971 103 | 128,K2P3,Fmmm,mp-8262,0.7095000000000002,0.0001437069999994378,10,1.9148645466766194 104 | 115,TeI,C2/m,mp-569766,0.7162999999999999,0.0,8,4.92231570155831 105 | 189,TePb,Pnma,mp-685022,0.7206000000000001,0.05811223624999995,8,7.9180889736950855 106 | 137,MgP4,P2_1/c,mp-384,0.7289000000000003,0.0,10,2.46614174038255 107 | 171,ZnO,P6_3mc,mp-2133,0.7303,0.0,4,5.437863970738863 108 | 0,AgBr,Fm-3m,mp-23231,0.7306000000000001,0.037009185000000056,2,6.2245796746989335 109 | 208,Tl2Te3,C2/c,mp-29711,0.7326999999999995,0.0,10,7.48690518832238 110 | 81,Cs2Se3,Cmc2_1,mp-7449,0.7396,0.0,10,4.092482945935117 111 | 195,SiS4,P2_1/m,mp-1080657,0.7528999999999999,0.04592203237500225,10,2.0948575343549045 112 | 57,CrCl2,Pnnm,mp-22857,0.7548999999999997,0.062071819814816465,6,2.7382022475606744 113 | 68,Y2Cl3,C2/m,mp-27678,0.7587000000000002,0.0,10,3.43288515486648 114 | 184,PbS,P2_1/m,mp-1078696,0.7614000000000001,0.08290959875000059,8,6.490216495860211 115 | 177,Rb2P3,Fmmm,mp-2079,0.7643999999999997,0.0,10,2.6439835472020095 116 | 5,AgI,Fm-3m,mp-22919,0.7690000000000001,0.09201829499999992,2,6.642205533656918 117 | 51,CdP4,P2_1/c,mp-7904,0.7775999999999996,0.008935772261905228,10,3.715975646741477 118 | 102,GaTe,P6_3/mmc,mp-10009,0.7804000000000002,0.00398078249999978,8,4.804721875203941 119 | 45,CaH2,P6_3/mmc,mp-24809,0.7814000000000001,0.055924374166666624,6,2.077239518232828 120 | 64,PdCl2,P2_1/c,mp-1018891,0.7861999999999999,0.011780776111111724,6,3.841986491536187 121 | 207,ThTe3,P2_1/m,mp-1025522,0.7904,0.0,8,6.844257691326957 122 | 146,MnS,Fm-3m,mp-850034,0.7927,0.06038237749999986,2,4.296224023705183 123 | 162,SnO2,Pnnm,mp-550172,0.8060999999999998,0.0022980783333332866,6,6.627866019824383 124 | 138,MgTe,P6_3/mmc,mp-1017510,0.8062999999999994,0.04766248750000024,4,4.711137948059274 125 | 188,TePb,Fm-3m,mp-19717,0.8071999999999999,0.0,2,7.856996892898824 126 | 26,BaTe3,P-42_1m,mp-8234,0.8122999999999996,0.011695468749999716,8,5.982170076085603 127 | 173,P2Os,Pnnm,mp-2319,0.815199999999999,0.0,6,9.334691977895638 128 | 18,Au2O3,Fdd2,mp-27253,0.8199999999999998,0.0,10,10.406697348337108 129 | 194,RbTe,Pbam,mp-8360,0.8245999999999998,0.02560945250000035,8,4.2409124787987045 130 | 192,PtSe2,P-3m1,mp-1115,0.8273999999999999,0.0,3,7.821288412821826 131 | 28,BiI,C2/m,mp-568388,0.8279000000000001,0.026354870833333877,8,6.10360416979927 132 | 144,MnS,F-43m,mp-850037,0.8285999999999998,0.0,2,3.4146613273119226 133 | 97,FeP4,C222_1,mp-568328,0.8292999999999999,0.012781697500013678,10,4.205289670125828 134 | 145,MnS,P6_3mc,mp-850036,0.8357000000000001,0.017909945000000427,4,3.3914214426246927 135 | 79,Cs2P3,Fmmm,mp-14652,0.8419000000000003,0.0,10,3.1937032224329265 136 | 135,Li3Sb,Fm-3m,mp-2074,0.8451,0.0,4,3.3521009485788444 137 | 199,TlS,I4/mcm,mp-322,0.8478000000000003,0.05039647015625537,8,7.043525786605017 138 | 69,ZrCl2,R3m,mp-23162,0.8481000000000005,0.0,3,3.855973688178949 139 | 38,NbBr4,C2/m,mp-1080428,0.8548,0.0,10,4.070716190256522 140 | 204,SnSe,P4/nmm,mp-8936,0.8548999999999999,0.04610063249999996,4,2.9087304711691977 141 | 191,Rb2Pd,Fm-3m,mp-1062711,0.8564,0.09060545333333314,3,3.285397513525638 142 | 167,VO2,Pnnm,mp-796076,0.8619000000000003,0.0016187450000000325,6,4.4701188875358016 143 | 92,RhF3,R-3c,mp-2068,0.8625999999999999,0.0,8,5.294263335540481 144 | 3,AgCl,P2_1/m,mp-570687,0.8727,0.011372675000000054,4,5.43384204755747 145 | 114,PdI2,Pnnm,mp-569017,0.8733000000000002,0.016237895000000613,6,4.8036344251807925 146 | 98,FeS2,Pnnm,mp-1522,0.8770000000000007,0.0,6,4.893651264940425 147 | 22,BaF3,P2_1/m,mp-1080821,0.8828,0.0,8,4.512646114255365 148 | 179,P4Ru,P2_1/c,mp-1080439,0.8846000000000007,0.01592549166666668,10,4.770503297563004 149 | 166,VO2,P4_2/mnm,mp-561572,0.8854000000000002,4.0393333334165504e-05,6,4.4469427458928354 150 | 182,PbS,Pnma,mp-1091375,0.8872999999999998,0.01862807749999984,8,7.148510878357764 151 | 39,PdBr2,C2/c,mp-27857,0.8979,0.0,6,4.066308824548829 152 | 105,GeSe,Pnma,mp-700,0.8988,0.0,8,5.121946569342683 153 | 65,PdCl2,Pnnm,mp-569008,0.9097,0.0289248211111115,6,3.3717491426807986 154 | 62,NiCl2,R-3m,mp-27396,0.9162999999999999,0.0,3,3.2213106317255984 155 | 73,CoO2,P-3m1,mp-32686,0.9177999999999997,0.026684935833331203,3,5.069094634781237 156 | 7,AlSb,P6_3mc,mp-1018100,0.9179000000000004,0.008148902500000332,4,4.0797275731576725 157 | 25,BaSe3,P-42_1m,mp-7548,0.9260000000000002,0.004225005351561784,8,5.2500956803326515 158 | 210,Te2W,P6_3/mmc,mp-1019322,0.9395999999999995,0.02538069583333602,6,8.823618216389502 159 | 85,CuI,Cmcm,mp-1007922,0.9427000000000003,0.05679269000000042,4,5.259605776738203 160 | 2,AgCl,Fm-3m,mp-22922,0.9539000000000002,0.0,2,5.356179410569647 161 | 46,Ca3N2,R-3c,mp-1047,0.9554,0.013622313750000004,10,2.666963754268679 162 | 104,GeS2,P4_2/nmc,mp-1071032,0.9558,0.09621701770833013,6,3.1621418909033108 163 | 101,Ga2Te5,I4/m,mp-2371,0.9569999999999999,0.0,7,5.500923886588706 164 | 118,In2O3,R-3c,mp-22323,0.9578999999999995,0.029491442000000312,10,6.941641659064563 165 | 89,IrF3,R-3c,mp-2437,0.9611000000000001,0.0030829731250046066,8,8.039138818626087 166 | 147,Te2Mo,P6_3/mmc,mp-602,0.9657,0.0,6,6.9283524242671515 167 | 88,HgF2,Fm-3m,mp-8177,0.9684,0.0,3,8.773296180515459 168 | 66,PdCl2,P2/m,mp-1018888,0.9724,0.02898144444444517,6,3.3227999223576825 169 | 133,Li3N,P6/mmm,mp-2251,0.9840000000000001,0.0,4,1.288609010112388 170 | 34,CuBr,P4/nmm,mp-22917,0.9948999999999999,0.002187302499999877,4,5.155570583051072 171 | 21,SrB6,Pm-3m,mp-242,1.0040999999999993,0.0,7,3.41706056581185 172 | 42,YbC2,I4/mmm,mp-1100,1.0157,0.05221974374999405,3,6.992808010747606 173 | 17,CsAu,Pm-3m,mp-2667,1.0239,0.0,2,6.51413454968331 174 | 211,ZnTe,F-43m,mp-2176,1.0290000000000004,0.0,2,5.418812150992769 175 | 111,HgSe,P3_221,mp-1018722,1.0322,0.03712615500000016,6,7.782780801317708 176 | 205,Tl2Se3,C2/c,mp-1080677,1.0324,0.013060627281249904,10,7.269722094359688 177 | 8,Al2Te5,C2/m,mp-9254,1.0356,0.0,7,4.45691696598753 178 | 100,Ga2Se3,Cc,mp-1340,1.0376,0.0,10,4.767617685594667 179 | 53,CdS,F-43m,mp-2469,1.0461,0.001219669999999784,2,4.576805151119732 180 | 70,CoO,F-43m,mp-715460,1.0476,0.0,2,5.136134319244935 181 | 200,ZrS2,P-3m1,mp-1186,1.0478000000000003,0.0,3,3.3074690414665873 182 | 117,VI2,P-3m1,mp-1018138,1.0495999999999994,0.0,3,4.8369459491521924 183 | 6,Ag2S,P2_1/m,mp-556225,1.0608000000000004,0.005376126666668757,6,6.503843619551617 184 | 212,ZnTe,P3_1,mp-571195,1.069,0.0031023566666665836,6,5.424327957909449 185 | 150,WN2,P-6m2,mp-999549,1.0696000000000003,0.0,3,12.066237758071253 186 | 41,WBr6,R-3,mp-28483,1.0697999999999999,0.0,7,4.176017674392683 187 | 198,SrS3,Aea2,mp-1175,1.0703,0.0,8,2.960341116098919 188 | 20,BP,P6_3mc,mp-1008559,1.0757000000000003,0.011565962499999749,4,2.953063012125262 189 | 61,NbCl4,C2/m,mp-31040,1.0765,0.0,10,2.5853158048727876 190 | 126,InSe,C2/m,mp-21405,1.0795999999999997,0.03557385625000009,8,5.390145613069638 191 | 213,ZnTe,P6_3mc,mp-8884,1.1007000000000002,0.00630044250000017,4,5.409812514466139 192 | 75,CoO2,P-3m1,mp-714965,1.1057,0.031195422499999736,3,4.778501127862719 193 | 82,CsTe,Pbam,mp-8361,1.1129000000000002,0.0,8,4.534722913096248 194 | 190,TePb,Pnma,mp-1079574,1.1150000000000002,0.06500985625000011,8,7.470658337330211 195 | 132,LaN,P6_3mc,mp-567290,1.1159,0.0,4,5.760192281896169 196 | 52,CdS,P6_3mc,mp-672,1.1162,0.0,4,4.575653035542619 197 | 74,CoO2,P-3m1,mp-714976,1.1166,0.02668493583333209,3,4.786926248757031 198 | 187,PbSe,Pnma,mp-1079172,1.1181000000000005,0.07581480999999979,8,7.307260647400709 199 | 91,PtF4,Fdd2,mp-8943,1.1225,0.0,10,6.560004429214969 200 | 40,VBr2,P-3m1,mp-971787,1.1314000000000002,0.0,3,4.0659056898565655 201 | 196,SnS,Cmcm,mp-1379,1.1323000000000003,0.06303699750000025,4,3.7528150226777495 202 | 197,SnS,Cmcm,mp-1040453,1.1323000000000003,0.0631273650000006,4,3.752815154590932 203 | 107,HfS3,P2_1/m,mp-9922,1.1326,0.0,8,5.091838313294505 204 | 67,PtCl2,Pnnm,mp-567484,1.1359,0.04472348277777982,6,5.126924527926468 205 | 116,TiI4,C2/c,mp-541013,1.1383999999999999,0.0,10,4.366868798781903 206 | 186,PbSe,Cmcm,mp-1063670,1.1440000000000001,0.0523708850000002,4,7.9527438504150005 207 | 170,WO3,P4/nmm,mp-19443,1.1455,0.00018257249999820147,8,6.656532869927425 208 | 163,TeO3,R-3c,mp-2552,1.1502999999999997,0.0,8,5.995793760035555 209 | 27,Be2C,Fm-3m,mp-1569,1.1636999999999995,0.0,3,2.4612616266066016 210 | 113,MnI2,P-3m1,mp-28013,1.1639,0.0,3,4.463106156174579 211 | 206,ZnSe,F-43m,mp-1190,1.1663,0.0,2,5.064264571986021 212 | 71,CoO,P6_3mc,mp-715448,1.1707999999999998,0.006644137499999481,4,5.105816576613445 213 | 29,Bi2O3,P-3m1,mp-1017552,1.1772,0.06983053549999951,5,9.859558488712516 214 | 110,HgO,Pnma,mp-1224,1.1867,0.0,8,9.849066293204165 215 | 72,CoO2,R-3m,mp-1062939,1.1944000000000001,0.023542509166666115,3,4.4399989831628215 216 | -------------------------------------------------------------------------------- /Scripts/Pymatgen/work/Gap_screen-4.csv: -------------------------------------------------------------------------------- 1 | ,Formula,Space group,Material_id,Gap,e_above_hull,N_sites,Density 2 | 65,LiIn2CuSe4,I-4,mp-1079491,0.4106000000000001,0.004643349374999772,8,4.88517001017933 3 | 70,SrGaSnH,P3m1,mp-978852,0.4150999999999998,0.0,4,5.106885028936842 4 | 69,SrGaSiH,P3m1,mp-979137,0.4166000000000003,0.0,4,4.091729385300156 5 | 28,Ba3ZnN2O,P4/mmm,mp-545788,0.42289999999999983,0.00724865857142909,7,5.410371231605409 6 | 29,Ba2ZnTeO6,Fm-3m,mp-1078410,0.4314999999999998,0.0,10,6.6360455898021 7 | 55,Sr2HfCrO6,Fm-3m,mp-1095039,0.4405999999999999,0.035030434312510295,10,6.499273462810511 8 | 56,Sr2CrOsO6,R-3,mp-1078448,0.4546999999999999,0.0,10,6.841311132825583 9 | 21,BaGaSiH,P3m1,mp-1008506,0.47920000000000007,0.0,4,4.643219179409462 10 | 59,EuCuSF,P4/nmm,mp-21354,0.49069999999999947,0.0,8,6.6738692754246225 11 | 14,BaCuB2O5,C2,mp-551135,0.49439999999999995,0.03228256592591805,9,4.066482035020825 12 | 45,CaGaGeH,P3m1,mp-1018093,0.5002,0.0,4,4.250074985071862 13 | 49,Cs2NaUCl6,Fm-3m,mp-23108,0.5004,0.018912803749999263,10,3.6098280720389497 14 | 42,Rb2Pd(IBr2)2,I4/mmm,mp-567948,0.5302,0.009486033611111555,9,4.30463025472718 15 | 74,MnSbSe2I,C2/m,mp-570268,0.532,0.0,10,5.496406388815925 16 | 3,AgPbBrO,P4/nmm,mp-559470,0.5365999999999997,0.05232092073863104,8,5.909104684742295 17 | 72,GdZnPO,R-3m,mp-545506,0.5424999999999995,0.0,8,6.5339835804028885 18 | 5,KAg2SbS4,I-42m,mp-9490,0.5695999999999999,0.0011462225781242452,8,3.921085229594302 19 | 12,LaZnAsO,P4/nmm,mp-549589,0.5760000000000005,0.0,8,6.329917672615641 20 | 1,BaAg2GeS4,I-42m,mp-7394,0.5888,0.0,8,4.70604322824128 21 | 61,CuH4(OF)2,C2/m,mp-1080513,0.5986000000000001,0.026358988333337052,9,2.5524722903299515 22 | 47,Sr2Co(ClO)2,I4/mmm,mp-24840,0.5993000000000004,0.00018267809523742073,7,4.3478318351941 23 | 31,CuBiSCl2,Cmcm,mp-554238,0.6101000000000001,0.03718448162499932,10,5.558120645677588 24 | 4,Cs2KAgF6,Fm-3m,mp-13687,0.6207999999999999,0.0,10,4.2029998693191954 25 | 39,Sr2Co(BrO)2,I4/mmm,mp-24866,0.6307,9.287595238038904e-05,7,4.82564083219074 26 | 11,GdZnAsO,P4/nmm,mp-1078542,0.6312000000000002,0.0,8,7.206813937243346 27 | 7,SrAlSiH,P3m1,mp-570485,0.6337000000000002,0.0,4,3.1024449975564887 28 | 77,LaZnPO,P4/nmm,mp-7060,0.6563000000000008,0.0,8,5.6916119330771116 29 | 43,MnSbS2Br,C2/m,mp-554061,0.6707999999999998,0.019817425000001165,10,4.516465729857913 30 | 76,LaTaN2O,C2/m,mp-550514,0.6712999999999996,0.0,10,9.057114745019012 31 | 40,Cs2Pd(IBr2)2,I4/mmm,mp-543024,0.6798000000000001,0.0,9,4.544991937812826 32 | 41,Cs2Pd(IBr2)2,C2/m,mp-23099,0.6891,0.0021896733333330864,9,4.541991545986941 33 | 10,SrZnAsF,P4/nmm,mp-1080135,0.69,0.0,8,5.180440709733505 34 | 16,BaYbCdSb2,Cmc2_1,mp-865143,0.7040000000000002,0.0,10,6.571966930842841 35 | 6,BaAlSiH,P3m1,mp-571093,0.7094,0.0,4,3.7511084947395275 36 | 0,Cs2AgAuCl6,I4/mmm,mp-567776,0.7122999999999999,0.0,10,4.094022118341053 37 | 36,MnBiSe2I,C2/m,mp-569109,0.7160000000000002,0.0,10,6.415721156432453 38 | 68,LiLa2FeO6,R-3,mp-1078209,0.7263999999999999,0.0,10,6.184173006655459 39 | 71,Sr2GaSbO6,Fm-3m,mp-6065,0.7291000000000003,0.03867083287500073,10,6.053917064672321 40 | 79,SrTaNO2,I4/mcm,mp-552454,0.7545000000000002,0.04593134249997988,10,7.85742408572095 41 | 50,Cu3TeS3Cl,R3m,mp-557510,0.7738999999999994,0.028055906367188577,8,4.583606777825174 42 | 17,BaGd2CoO5,Immm,mp-561746,0.8241,0.07248366907407089,9,7.602948296780887 43 | 80,NdZnSbO,P4/nmm,mp-12516,0.8324999999999996,0.0,8,6.794907912029294 44 | 52,Sr2CoMoO6,I4/mmm,mp-560723,0.8403,0.08343698800000254,10,5.656226657903529 45 | 57,Cs2KCuF6,Fm-3m,mp-6968,0.8474999999999999,0.0,10,4.224607909838752 46 | 32,GdBi2ClO4,P4/mmm,mp-549695,0.8529,0.0,8,8.042075945504175 47 | 23,Ba2GdMoO6,I4/m,mp-1078907,0.8590999999999998,0.0006706570000147849,10,6.585204569403332 48 | 13,NdZnAsO,P4/nmm,mp-7061,0.8621999999999996,0.0,8,6.627586293717698 49 | 27,Ba2SmMoO6,I4/m,mp-1095110,0.8754000000000004,0.0,10,6.411948229675473 50 | 48,Cs2Pd(ICl2)2,I4/mmm,mp-607298,0.8764000000000001,0.005611032222221368,9,4.001133745845254 51 | 35,SrBiS2F,P4/nmm,mp-1078631,0.8856000000000002,0.0022966052500006384,10,5.354333270484887 52 | 60,EuCuTeF,P4/nmm,mp-13339,0.8862000000000005,0.010900479375000494,8,7.3182995099501955 53 | 38,TiZn(BiO3)2,P4mm,mvc-11630,0.8966999999999992,0.0722009985000005,10,7.312611601488466 54 | 37,LaBiSe2O,P4/nmm,mp-1078431,0.9102000000000006,0.014555732000001598,10,6.765564769027161 55 | 20,Ba2ThCu2Se5,C2/m,mp-1078405,0.9245000000000005,0.0,10,6.261531960456166 56 | 62,K2NaCuF6,Fm-3m,mp-13797,0.9263,0.0,10,3.1562451378224665 57 | 44,Eu2C(NCl)2,C2/m,mp-582618,0.9358999999999993,0.0,7,4.699435512165045 58 | 9,BaCdAsF,P4/nmm,mp-1095151,0.9570000000000003,0.0,8,5.882471309373822 59 | 22,Ba2GdMoO6,P-1,mp-1079839,0.9748999999999999,0.0,10,6.55634530566938 60 | 26,Ba2NdMoO6,P-1,mp-1078551,0.9790000000000005,0.00020298399999862937,10,6.272371875896516 61 | 30,GdBi2BrO4,P4/mmm,mp-562809,0.9891000000000001,0.0,8,8.187903345210758 62 | 25,Ba2UMnO6,Fm-3m,mp-25003,1.0436,0.0,10,6.989746757139487 63 | 8,Nd2AlNO3,I4mm,mp-546679,1.0619999999999994,0.07632814321433123,7,7.1351881468985 64 | 2,AgBiSCl2,Cmcm,mp-556094,1.0686999999999998,0.0,10,5.553840234301503 65 | 18,Ba2CoMoO6,I4/mmm,mp-561894,1.0715999999999997,0.05368443816667323,10,6.3910218137008545 66 | 46,Ca2TiMnO6,I4/m,mp-1080507,1.0729999999999995,0.022327083958336047,10,4.165976130667727 67 | 19,Ba2ThCu2S5,C2/m,mp-1078630,1.0797000000000008,0.0,10,5.44732955796699 68 | 78,Sr2MnMoO6,I4/m,mp-1095141,1.0968000000000004,0.007963156499998902,10,5.261482369271702 69 | 51,Sr2CoMoO6,I4/m,mp-18805,1.1019999999999994,0.0,10,5.529610001233701 70 | 34,PrBi2ClO4,P4/mmm,mp-553082,1.1244,0.0,8,7.559525516614453 71 | 66,K2Th(CuS2)2,C2/m,mp-555425,1.1260000000000003,0.010681548611112035,9,4.482918957196105 72 | 54,Na5CoSO2,P4/mmm,mp-558872,1.1386999999999998,0.012576911944443658,9,2.2818748149680417 73 | 53,Na5CoSO2,P4/mmm,mp-19027,1.1386999999999998,0.012245121944453707,9,2.2888981893257956 74 | 24,Ba2MnTeO6,Fm-3m,mp-18992,1.1448,0.0,10,6.335366306820531 75 | 15,BaCdPF,P4/nmm,mp-1079603,1.1477,0.01003422750000027,8,5.367492164938959 76 | 73,Rb2SnHgTe4,I-42m,mp-1080691,1.1515,0.0,8,5.305613565033333 77 | 81,PrZnPO,R-3m,mp-13206,1.1665,0.0,8,5.728012605770079 78 | 58,DyCuSeO,P4/nmm,mp-9304,1.1804000000000006,0.016320074375000715,8,8.039123733644027 79 | 75,La2MnNiO6,Fm-3m,mp-1079517,1.1807999999999996,0.0,10,6.8871865199144535 80 | 33,NdBi2ClO4,P4/mmm,mp-545529,1.1834999999999996,0.0,8,7.640611702508007 81 | 64,GdCuSeO,P4/nmm,mp-561820,1.1960999999999995,0.0038370381250008023,8,7.7016291304604 82 | 67,LaCuTeO,P4/nmm,mp-546790,1.1965999999999992,0.006948040625000651,8,6.999247910075809 83 | 63,SrCuSeF,P4/nmm,mp-21228,1.1989,0.0009549143749998379,8,5.546136990410341 84 | -------------------------------------------------------------------------------- /Scripts/Pymatgen/work/gap_screen.py: -------------------------------------------------------------------------------- 1 | from pymatgen import MPRester 2 | import numpy as np 3 | import pandas as pd 4 | from tabulate import tabulate 5 | 6 | mpr = MPRester('fn8WQGgT9rvZAh6H') 7 | gap_min, gap_max = 0.4, 1.2 8 | 9 | 10 | tag = [1, 2, 3, 4] 11 | for nele in tag: 12 | col_name = {'Formula': [], 13 | 'Space group': [], 14 | 'Material_id': [], 15 | 'Gap': [], 16 | 'e_above_hull': [], 17 | 'N_sites': [], 18 | 'Density': [], 19 | } 20 | 21 | entries = mpr.query(criteria={"band_gap": {"$lte": gap_max}, 22 | "icsd_ids.0": {'$exists': True}, 23 | "nsites": {"$lte": 10}, 24 | "e_above_hull": {"$lte": 0.1}, 25 | "nelements": nele, 26 | }, 27 | properties=["pretty_formula", 28 | "material_id", 29 | # "structure", 30 | "e_above_hull", 31 | "spacegroup.symbol", 32 | "band_gap", 33 | "nsites", 34 | "density", 35 | ] 36 | ) 37 | 38 | for entry in entries: 39 | if entry["band_gap"] > gap_min: 40 | col_name['Formula'].append(entry['pretty_formula']) 41 | col_name['Space group'].append(entry['spacegroup.symbol']) 42 | col_name['Material_id'].append(entry['material_id']) 43 | col_name['e_above_hull'].append(entry['e_above_hull']) 44 | col_name['Gap'].append(entry['band_gap']) 45 | col_name['N_sites'].append(entry['nsites']) 46 | col_name['Density'].append(entry['density']) 47 | 48 | 49 | df = pd.DataFrame(col_name) 50 | df = df.sort_values(['Gap'], ascending=[True]) 51 | df.to_csv('Gap_screen-'+str(nele)+'.csv') 52 | # print(tabulate(df, headers='keys', tablefmt='psql')) 53 | -------------------------------------------------------------------------------- /Scripts/README.md: -------------------------------------------------------------------------------- 1 | # Scripts 2 | A collection of scripts that are used to process data based on different packages 3 | 4 | - ASE 5 | - AFLOW 6 | - CSD 7 | - Pymatgen 8 | - USPEX 9 | 10 | -------------------------------------------------------------------------------- /Scripts/USPEX/Extract_USPEX.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # encoding: utf-8 3 | 4 | ''' 5 | $Author: Qiang Zhu $ 6 | $Date: 2018-10-01 18:38:44 $ 7 | 1, to check if USPEX calc generates the reference structure: 8 | $ python Extract_USPEX.py -c POSCAR 9 | 10 | 2, to extract good structures from the calculation 11 | $ python Extract_USPEX.py 12 | ''' 13 | 14 | import os 15 | from pymatgen.symmetry.analyzer import SpacegroupAnalyzer 16 | import pymatgen as mg 17 | import pymatgen.analysis.structure_matcher as sm 18 | from optparse import OptionParser 19 | import scipy.io as sio 20 | import numpy as np 21 | import pandas as pd 22 | from tabulate import tabulate 23 | from pymatgen.io.vasp import Poscar 24 | from pymatgen.io.cif import CifWriter 25 | 26 | def export_structure(struc, filename, fileformat='poscar'): 27 | with open(filename, 'w') as f: 28 | for s in struc: 29 | if fileformat == 'poscar': 30 | content = s.to(fmt='poscar') 31 | else: 32 | content = CifWriter(struc, symprec=0.01).write_file() 33 | f.writelines(content) 34 | 35 | #------------------------------------------------------------------ 36 | #-------------------------------- Options ------------------------- 37 | parser = OptionParser() 38 | parser.add_option("-m", "--mat", dest="matfile", default='USPEX.mat', 39 | help="MATLAB .mat file, default: USPEX.mat", metavar="FILE") 40 | parser.add_option("-n", "--Nmax", dest="Nmax", default=30, type='int', 41 | help="maximum number of strucs to output", metavar="Max") 42 | parser.add_option("-c", "--compare", dest="compare", 43 | help="compare reference structure", metavar="compare") 44 | parser.add_option("-t", "--tolerance", dest="tol", default=0.05, type='float', 45 | help="symmetry tolerance", metavar="tol") 46 | parser.add_option("-e", "--export", dest="export", default='poscar', 47 | help="export format: cif or poscar", metavar="export") 48 | 49 | (options, args) = parser.parse_args() 50 | 51 | if not os.path.exists(options.matfile): 52 | error_str = 'No ' + options.matfile + ' file found.' 53 | parser.error(error_str) 54 | 55 | matfile = options.matfile 56 | mat = sio.loadmat(matfile, struct_as_record=True) 57 | POP = mat['USPEX_STRUC'] 58 | 59 | POPULATION = POP['POPULATION'] 60 | N_struc = POPULATION[0][0].shape[1] 61 | print('{0:d} structures have been loaded'.format(N_struc)) 62 | 63 | Nmax = options.Nmax 64 | parser.destroy() 65 | 66 | #------------------------------------------------------------------- 67 | Element = [] 68 | for i in POP['SYSTEM'][0][0][0][0][1][0,:]: Element.append(' '.join(map(str, i))) 69 | 70 | Struc = [] 71 | Energy = [] 72 | Origin = [] 73 | Fitness = [] 74 | for i in range(N_struc): 75 | coord = POPULATION[0][0]['COORDINATES'][0][i] 76 | lattice = POPULATION[0][0]['LATTICE'][0][i] 77 | numIons = POPULATION[0][0]['numIons'][0][i] 78 | howcome = POPULATION[0][0]['howCome'][0][i][0] 79 | energy = POPULATION[0][0]['Enthalpies'][0][i][0][-1] 80 | fitness = POPULATION[0][0]['Fitness'][0][i][0][-1] 81 | 82 | s = []; 83 | for el,num in zip(Element,numIons[0]): s = s + ([el]*num) 84 | Struc.append(mg.Structure(lattice, s, coord)) 85 | Origin.append(howcome) 86 | Energy.append(energy/sum(numIons[0])) 87 | Fitness.append(fitness) 88 | 89 | if options.compare: 90 | # check 91 | s1 = mg.Structure.from_file(options.compare) 92 | for i, s0 in enumerate(Struc): 93 | dist = sm.StructureMatcher().fit(s1, s0) 94 | p1 = ['{:6.3f}'.format(j) for j in s0.lattice.abc] 95 | p2 = ['{:6.2f}'.format(j) for j in s0.lattice.angles] 96 | s = ' '.join(map(str,p1+p2)) 97 | spg = SpacegroupAnalyzer(s0, symprec=options.tol).get_space_group_symbol() 98 | print('{0:4d} {1:40s} {2:12s} {3:9.3f} {4:10s} {5:4b}'.format(i+1, s, spg, Energy[i], Origin[i], dist)) 99 | if dist: 100 | break 101 | else: 102 | Fitness = np.array(Fitness) 103 | Ranking = np.argsort(Fitness) 104 | ids = [Ranking[0] + 1] 105 | struc_out = [Struc[Ranking[0]]] 106 | energy_out = [Energy[Ranking[0]]] 107 | fitness_out = [Fitness[Ranking[0]]] 108 | for i in Ranking[1:]: 109 | inc = True 110 | s0 = Struc[i] 111 | for s1 in struc_out: 112 | if sm.StructureMatcher().fit(s0, s1): 113 | inc = False 114 | break 115 | if inc: 116 | struc_out.append(s0) 117 | energy_out.append(Energy[i]) 118 | fitness_out.append(Fitness[i]) 119 | ids.append(i+1) 120 | 121 | if len(struc_out) == Nmax: 122 | break 123 | 124 | label_out = [] 125 | spg_out = [] 126 | formula_out = [] 127 | for s0 in struc_out: 128 | p1 = ['{:6.3f}'.format(j) for j in s0.lattice.abc] 129 | p2 = ['{:6.2f}'.format(j) for j in s0.lattice.angles] 130 | s = ' '.join(map(str,p1+p2)) 131 | label_out.append(s) 132 | spg_out.append(SpacegroupAnalyzer(s0, symprec=options.tol).get_space_group_symbol()) 133 | formula_out.append(s0.formula.replace(" ","")) 134 | col = {'ID': ids, 135 | 'Formula': formula_out, 136 | 'Space Group': spg_out, 137 | 'Cell': label_out, 138 | 'Energy': energy_out, 139 | 'Fitness': fitness_out, 140 | } 141 | 142 | df = pd.DataFrame(col) 143 | print('Below are the selected low energy structures by removing the duplicates') 144 | print(tabulate(df, headers='keys', tablefmt='psql')) 145 | filename = 'extracted.' + options.export 146 | export_structure(struc_out, filename, fileformat=options.export) 147 | print('The extracted structure info has been saved to {0:s}'.format(filename)) 148 | -------------------------------------------------------------------------------- /Scripts/USPEX/POSCAR: -------------------------------------------------------------------------------- 1 | Ti4 Se8 2 | 1.0 3 | 9.016744 -1.246465 -0.754286 4 | -1.781662 6.916359 -0.085675 5 | -0.326822 -0.043956 3.253763 6 | Ti Se 7 | 4 8 8 | direct 9 | 0.998463 0.630565 0.750018 Ti 10 | 0.430212 0.791722 0.966752 Ti 11 | 0.237689 0.205523 0.369933 Ti 12 | 0.669566 0.366189 0.586200 Ti 13 | 0.447151 0.163956 0.974706 Se 14 | 0.878476 0.322672 0.189762 Se 15 | 0.789619 0.673953 0.146434 Se 16 | 0.220725 0.833308 0.361602 Se 17 | 0.188130 0.443511 0.844884 Se 18 | 0.650925 0.986898 0.576090 Se 19 | 0.017048 0.010084 0.760450 Se 20 | 0.480045 0.553803 0.491927 Se 21 | -------------------------------------------------------------------------------- /Scripts/USPEX/README.md: -------------------------------------------------------------------------------- 1 | This code `Extract_USPEX.py` is used for quick analysis of USPEX results solely from USPEX.mat. It has the following features: 2 | 3 | - extract good structures by ranking of fitness (with the removal of duplicates) 4 | - check if a desired structure has been found in USPEX 5 | 6 | ## Prerequisites 7 | To use it, one must have python 3 installed. 8 | In addition, several packages will be required 9 | - pymatgen 10 | - pandans 11 | 12 | One could follow the [wikipage](https://github.com/qzhu2017/CMS/wiki/Python-environment-setup) to set up your python environment. 13 | ``` 14 | $ python Extract_USPEX.py -h 15 | Usage: Extract_USPEX.py [options] 16 | 17 | Options: 18 | -h, --help show this help message and exit 19 | -m FILE, --mat=FILE MATLAB .mat file, default: USPEX.mat 20 | -n Max, --Nmax=Max maximum number of strucs to output 21 | -c compare, --compare=compare 22 | compare reference structure 23 | -t tol, --tolerance=tol 24 | symmetry tolerance 25 | -e export, --export=export 26 | export format: cif or poscar 27 | ``` 28 | 29 | 30 | ## Extract good structures 31 | 32 | ``` 33 | $ python Extract_USPEX.py 34 | 1420 structures have been loaded 35 | Below are the selected low energy structures by removing the duplicates 36 | +----+------+-----------+---------------+------------------------------------------+----------+-----------+ 37 | | | ID | Formula | Space Group | Cell | Energy | Fitness | 38 | |----+------+-----------+---------------+------------------------------------------+----------+-----------| 39 | | 0 | 1211 | Ti4Se8 | C2/m | 9.134 7.143 3.270 90.00 100.31 112.17 | -3.72337 | -44.6804 | 40 | | 1 | 714 | Ti4Se8 | C2/m | 3.325 9.408 6.514 99.51 104.59 90.05 | -3.69974 | -44.3969 | 41 | | 2 | 923 | Ti4Se8 | C2/c | 3.321 4.974 12.624 80.74 90.20 109.29 | -3.69794 | -44.3753 | 42 | | 3 | 1327 | Ti4Se8 | Cm | 3.349 9.866 6.473 71.63 104.89 99.57 | -3.69537 | -44.3444 | 43 | | 4 | 544 | Ti4Se8 | Cmc2_1 | 3.306 9.416 6.494 90.03 75.37 90.00 | -3.69153 | -44.2983 | 44 | | 5 | 163 | Ti4Se8 | C2/m | 6.128 6.458 6.135 118.00 114.00 79.17 | -3.69011 | -44.2813 | 45 | | 6 | 1053 | Ti4Se8 | C2/m | 9.668 6.504 3.296 75.33 99.72 100.46 | -3.68417 | -44.21 | 46 | | 7 | 573 | Ti4Se8 | P-3m1 | 5.473 5.644 6.601 90.00 90.01 89.78 | -3.66893 | -44.0272 | 47 | | 8 | 949 | Ti4Se8 | Pnma | 6.936 8.692 3.178 89.99 90.00 90.00 | -3.65972 | -43.9166 | 48 | ``` 49 | In addition, a new file called `extracted.poscar` or `extracted.cif` will be generated. 50 | 51 | ## Check if the reference structure exists 52 | ``` 53 | $ python Extract_USPEX.py -c POSCAR 54 | 1011 5.951 6.945 6.191 67.32 116.88 89.64 P1 -3.340 Random 0 55 | 1012 6.517 6.765 4.953 89.24 108.76 75.17 P1 -3.447 Permutate 0 56 | 1013 6.630 4.928 6.421 100.32 75.61 78.40 P-1 -3.561 Permutate 0 57 | 1014 4.861 6.630 6.428 104.97 91.40 89.87 C2/m -3.595 Permutate 0 58 | 1015 4.685 9.452 4.799 89.18 79.05 86.13 P1 -3.211 Heredity 0 59 | 1016 5.869 6.096 5.872 86.27 85.44 80.43 P1 -3.428 Heredity 0 60 | 1017 3.297 7.460 8.596 95.68 100.96 102.75 Cm -3.438 Heredity 0 61 | 1018 6.139 6.206 6.109 88.13 75.57 112.73 P1 -3.446 Random 0 62 | 1019 8.481 7.204 3.323 90.04 89.85 107.15 C2/m -3.696 softmutate 0 63 | 1020 9.134 7.143 3.270 90.00 100.31 112.17 C2/m -3.723 softmutate 1 64 | ``` 65 | The search will start from the 1st structure and stop when the structure was found at the first place. 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /Scripts/USPEX/USPEX.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/Scripts/USPEX/USPEX.mat -------------------------------------------------------------------------------- /Tutorials/Convex_hull/1.txt: -------------------------------------------------------------------------------- 1 | 8.532873317240492472e-01 5.832076253130925592e-01 2 | 9.080789022842893354e-01 8.296121144766333000e-02 3 | 2.576410693990823786e-01 9.355397824475477631e-01 4 | 9.188593488422082123e-01 1.404241875411655904e-01 5 | 6.281713475345150899e-01 5.718407664633178289e-01 6 | 3.162543320915249812e-01 2.068886285787198132e-01 7 | 3.695316441947282815e-01 6.670233987347492510e-01 8 | 8.370020950968278806e-01 9.667131806033585351e-01 9 | 7.746905080088657414e-01 5.386528373858826546e-01 10 | 8.179709442895238825e-01 8.557540437535888778e-01 11 | 7.991892503341097020e-01 4.021611175589631104e-01 12 | 2.198737424050872802e-01 4.100910867878582167e-01 13 | 5.235089490794403444e-01 1.707536010850527752e-01 14 | 9.280619811649527540e-01 5.106876879458135399e-01 15 | 6.606844143521564128e-01 4.974033501081365216e-01 16 | 3.616865862299202261e-01 4.534469578868718376e-01 17 | 6.061830413603641610e-02 3.825105678858852221e-01 18 | 4.235717703324530792e-01 6.913414909470949610e-02 19 | 4.440497324098191534e-02 1.513015819077311308e-01 20 | 5.764347491959791459e-01 2.338860121415597959e-03 21 | 4.859678721750770869e-01 4.634972900480538449e-01 22 | 9.646734217069403705e-01 8.955485413579356013e-02 23 | 8.027893080762492639e-01 5.435911911310398192e-02 24 | 6.663375837611268393e-01 4.970278404867517485e-01 25 | 7.378469180643643099e-02 3.982508526673707028e-01 26 | 4.075485437259940280e-01 7.064078741888699664e-01 27 | 9.675235310093084351e-01 1.423635724042865425e-01 28 | 5.665307112013034940e-01 2.006133678178507740e-01 29 | 4.423379353263829916e-01 6.611570205837109526e-01 30 | 5.081024637993879489e-01 7.878189596487948920e-01 31 | 2.402634345279557326e-01 9.611801124558714271e-01 32 | 7.672572395668318945e-01 6.760698752811655776e-02 33 | 5.418762088403393795e-01 9.406249841590685890e-01 34 | 2.027832270077033483e-01 4.936201989463450124e-01 35 | 9.814940447741136165e-01 6.997350305528546865e-01 36 | 7.663527450205439573e-01 1.466695378510619596e-01 37 | 6.434710982634270771e-01 3.614692157875232237e-02 38 | 9.035987000127043700e-02 1.828693344770264684e-01 39 | 9.867073023478689642e-02 9.910202498674802740e-02 40 | 1.387449003948837412e-02 2.821389001571759092e-01 41 | 8.372928846025093907e-01 6.584409158856041611e-01 42 | 1.037245409331433166e-02 4.267101718033382562e-01 43 | 3.172281395435015972e-01 4.191702422232893577e-01 44 | 5.530057034758655288e-01 5.116796964364711542e-02 45 | 9.061148275360452198e-01 6.644647128447570550e-01 46 | 3.012584394315317438e-01 3.685237304403643499e-01 47 | 8.689928775171517072e-01 2.753452986646370837e-01 48 | 9.007629245637035487e-01 8.018916315029965824e-01 49 | 5.392497031840404187e-02 1.853693360043479066e-01 50 | 6.331832980802030164e-01 2.436480686067022949e-01 51 | -------------------------------------------------------------------------------- /Tutorials/Convex_hull/Cr-B0.txt: -------------------------------------------------------------------------------- 1 | 48.574 0.137 2 | 46.419 0.121 3 | 45.349 0.115 4 | 45.184 0.041 5 | 44.197 0 6 | 48.525 0.221 7 | 48.311 0.221 8 | 45.169 0.114 9 | 41.778 0.033 10 | 39.132 0.016 11 | 34.26 0 12 | 32.346 0 13 | 29.845 0 14 | 45.482 0.269 15 | 44.423 0.161 16 | 44.225 0.129 17 | 41.681 0.098 18 | 41.256 0.059 19 | 39.241 0.056 20 | 37.702 0.02 21 | 36.121 0.016 22 | 35.595 0.016 23 | 29.96 0.006 24 | 28.622 0 25 | 24.662 0 26 | 44.16 0.484 27 | 43.641 0.219 28 | 43.175 0.2 29 | 42.967 0.145 30 | 42.36 0.131 31 | 40.977 0.096 32 | 39.366 0.071 33 | 38.883 0.06 34 | 37.499 0.047 35 | 34.816 0.043 36 | 30.586 0.041 37 | 30.312 0.028 38 | 28.827 0.02 39 | 22.94 0 40 | 42.9 0.349 41 | 42.7 0.253 42 | 42.588 0.216 43 | 40.188 0.124 44 | 39.206 0.076 45 | 36.649 0.061 46 | 34.611 0.052 47 | 34.229 0.049 48 | 32.739 0.048 49 | 30.547 0.046 50 | 29.97 0.042 51 | 28.56 0.038 52 | 28.043 0.037 53 | 27.297 0.026 54 | 26.474 0.024 55 | 25.785 0.024 56 | 21.433 0 57 | 38.547 0.402 58 | 36.698 0.302 59 | 36.672 0.286 60 | 35.505 0.198 61 | 33.375 0.129 62 | 32.104 0.119 63 | 30.747 0.118 64 | 29.471 0.087 65 | 29.242 0.07 66 | 28.074 0.068 67 | 35.282 0.678 68 | 35.151 0.565 69 | 34.917 0.536 70 | 33.692 0.51 71 | 33.517 0.404 72 | 33.05 0.357 73 | 32.877 0.226 74 | 31.696 0.195 75 | 31.177 0.181 76 | 30.522 0.18 77 | 30.25 0.179 78 | 29.298 0.177 79 | 29.222 0.162 80 | 29.082 0.152 81 | 28.916 0.147 82 | 27.701 0.138 83 | 27.667 0.13 84 | 26.413 0.129 85 | 26.392 0.106 86 | 24.143 0.104 87 | 22.612 0.102 88 | 32.035 0.67 89 | 31.971 0.409 90 | 31.81 0.37 91 | 31.693 0.328 92 | 31.605 0.311 93 | 31.05 0.284 94 | 30.614 0.247 95 | 30.335 0.243 96 | 30.28 0.236 97 | 29.208 0.234 98 | 28.546 0.226 99 | 28.138 0.205 100 | 28.042 0.2 101 | 27.93 0.193 102 | 27.778 0.186 103 | 27.662 0.181 104 | 27.38 0.178 105 | 27.324 0.171 106 | 25.771 0.17 107 | 25.282 0.169 108 | 25.128 0.128 109 | 24.117 0.127 110 | 18.043 0.123 111 | 11.854 0.12 112 | 30.071 0.652 113 | 30.042 0.503 114 | 29.809 0.485 115 | 29.782 0.431 116 | 29.779 0.387 117 | 29.599 0.379 118 | 29.427 0.341 119 | 29.371 0.325 120 | 29.36 0.322 121 | 28.583 0.319 122 | 28.481 0.317 123 | 28.143 0.301 124 | 27.702 0.301 125 | 27.256 0.294 126 | 26.935 0.268 127 | 26.897 0.252 128 | 26.86 0.222 129 | 26.619 0.222 130 | 25.95 0.222 131 | 24.2 0.207 132 | 22.601 0.206 133 | 22.054 0.198 134 | 22.029 0.198 135 | 21.238 0.186 136 | -------------------------------------------------------------------------------- /Tutorials/Convex_hull/convex_hull.py: -------------------------------------------------------------------------------- 1 | from os import path, walk, listdir 2 | from scipy.spatial import ConvexHull 3 | from optparse import OptionParser 4 | from vasprun import vasprun 5 | from pprint import pprint 6 | import pandas as pd 7 | import numpy as np 8 | from tabulate import tabulate 9 | import collections 10 | from pymatgen.symmetry.analyzer import SpacegroupAnalyzer 11 | from pymatgen import Structure 12 | 13 | def get_subdir(a_dir): 14 | return sorted([name for name in listdir(a_dir) 15 | if path.isdir(path.join(a_dir, name))]) 16 | 17 | def get_spg(data): 18 | atomNames = data["name_array"] 19 | latt = data["finalpos"]["basis"] 20 | pos = data["finalpos"]["positions"] 21 | crystal = Structure(latt, atomNames, pos) 22 | return SpacegroupAnalyzer(crystal,symprec=0.02).get_space_group_symbol() 23 | 24 | #------------------------------------------------------------------- 25 | parser = OptionParser() 26 | parser.add_option("-p", "--pdir", dest='pdir', default='./', 27 | help="by parent directory") 28 | parser.add_option("-f", "--filename", dest="file", default='vasprun.xml', 29 | help="vasprun.xml") 30 | 31 | (options, args) = parser.parse_args() 32 | 33 | total_dir = get_subdir(options.pdir) 34 | entries = [] 35 | 36 | for sub_dir in total_dir: 37 | file_path = options.pdir + '/' + sub_dir+'/'+options.file 38 | if path.exists(file_path): 39 | vasp_calc = vasprun(file_path) 40 | if vasp_calc.error is False: 41 | entries.append(vasp_calc.values) 42 | 43 | elements = [] 44 | for entry in entries: 45 | for ele in entry['elements']: 46 | if ele not in elements: 47 | elements.append(ele) 48 | 49 | print('The system contains the following elements: ', elements) 50 | if len(elements) > 2: 51 | print('Error, we only support the calculation for binary systems') 52 | 53 | else: 54 | ref = [1e+8]*len(elements) 55 | for i, ele in enumerate(elements): 56 | for entry in entries: 57 | ref0 = entry['calculation']['energy_per_atom'] 58 | #print(entry['elements']) 59 | if len(entry['elements']) == 1 and entry['elements'][0]==ele and ref[i] > ref0: 60 | ref[i] = ref0 61 | ref = np.array(ref) 62 | ref = np.reshape(ref, [1, len(elements)]) 63 | struc = collections.OrderedDict( 64 | {'formula':[],'e_dft':[],'e_formation':[], 65 | 'e_above_hull':[],'space_group':[]} 66 | ) 67 | pts= [] 68 | 69 | for entry in entries: 70 | N = np.array([0, 0]) 71 | if entry['composition'].get(elements[0]): 72 | N[0] = entry['composition'][elements[0]] 73 | if entry['composition'].get(elements[1]): 74 | N[1] = entry['composition'][elements[1]] 75 | x0 = N/sum(N) 76 | x0 = np.reshape(x0, [len(elements),1]) 77 | x = N[1]/sum(N) 78 | y0 = entry['calculation']['energy_per_atom'] 79 | y1 = y0 - np.dot(ref, x0) 80 | #print(x, ref, y0, y1) 81 | struc['formula'].append(entry['formula']) 82 | struc['space_group'].append(get_spg(entry)) 83 | struc['e_dft'].append(y0) 84 | struc['e_formation'].append(y1[0,0]) 85 | pts.append([x,y1[0,0]]) 86 | #print(struc['pts']) 87 | pts = np.array(pts) 88 | hull = ConvexHull(pts) 89 | 90 | for i, pt in enumerate(pts): 91 | x0, y0 = pt[0], pt[1] 92 | for simplex in hull.simplices: 93 | x, y = pts[simplex, 0], pts[simplex, 1] 94 | #print(x, y, x0, y0) 95 | if sum(y)<0 and max(y)<=0 and x0>=min(x) and x0<=max(x): 96 | e_tmp = y0- y[0] - (x0-x[0])*(y[1]-y[0])/(x[1]-x[0]) 97 | struc['e_above_hull'].append(e_tmp) 98 | break 99 | #pprint(struc) 100 | df = pd.DataFrame(struc) 101 | df = df.sort_values('e_above_hull', ascending=[True]) 102 | print(tabulate(df, headers='keys', tablefmt='psql')) 103 | -------------------------------------------------------------------------------- /Tutorials/HPC/cori.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/Tutorials/HPC/cori.pdf -------------------------------------------------------------------------------- /Tutorials/MD_Lammps_lecture/MD_Lammps.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/Tutorials/MD_Lammps_lecture/MD_Lammps.pdf -------------------------------------------------------------------------------- /Tutorials/ML/MLP model from the scratch.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Multi-Layer Perceptron from the scratch\n", 8 | "\n", 9 | "Nowadays, multi-Layer neural network has been proved to be a powerful tool in many data science problems. Though many existing packages have provided the interfaces to call this function (e.g. scikit-learn), it would be good to write some toy model by your own. Through this practice, you will gain some experience in software engineering. More importantly, you will understand the underlying mathmatics better and know how to fix the troubles when you run the code from the existing softwares. In the tutorial, we will continue to use the wine data and figure out how to write our own MLP classfier.\n", 10 | "\n", 11 | "Let us start with the example in the previous lecture\n", 12 | "```\n", 13 | "MLPClassifier(activation='relu', alpha=0.0001, batch_size='auto', beta_1=0.9,\n", 14 | " beta_2=0.999, early_stopping=False, epsilon=1e-08,\n", 15 | " hidden_layer_sizes=(4, 4), learning_rate='constant',\n", 16 | " learning_rate_init=0.001, max_iter=200, momentum=0.9,\n", 17 | " n_iter_no_change=10, nesterovs_momentum=True, power_t=0.5,\n", 18 | " random_state=None, shuffle=True, solver='adam', tol=0.0001,\n", 19 | " validation_fraction=0.1, verbose=False, warm_start=False)\n", 20 | "```\n", 21 | "\n", 22 | "
Figure 1, the MLP model used in this lecture
\n", 23 | "\n", 24 | "You should be able to understand most of the parameters at the moment. To realize a minimum version of MLP, we can try to implement the following parameters into our model:\n", 25 | "- hidden_layer_sizes: to make life easier, let us just consider 2 hidden layer models\n", 26 | "- max_iter: maximum number of iteractions\n", 27 | "- learning_rate_init: \n", 28 | "\n", 29 | "Note that we will completely ignore the terms related to regularization. \n", 30 | "We also need to choose the proper loss and activation functions. For simplicity, let's choose the followings,\n", 31 | "- Activation: Sigmoid\n", 32 | "- Loss: logloss\n", 33 | "\n", 34 | "## Forward propagation\n", 35 | "$\n", 36 | "\\begin{align}\n", 37 | "h_1 &= w_1\\cdot x + b_1\\\\\n", 38 | "z_1 & = f(h_1)\\\\\n", 39 | "h_2 &= w_2\\cdot f_1(w_1\\cdot x + b_1)) + b_2 = w_2\\cdot z_1 + b_2\\\\\n", 40 | "z_2 & = f(h_2)\\\\\n", 41 | "h_3 &= w_3\\cdot f_2((w_2\\cdot f_1(w_1\\cdot x + b_1)) + b_2)) + b_3 = w_3\\cdot z_2 + b_3\\\\\n", 42 | "y` &= f_3(h_3) \\\\\n", 43 | "\\end{align}\n", 44 | "$\n", 45 | "\n", 46 | "## Loss function (log loss): \n", 47 | "\n", 48 | "Logloss function is a popular choice for classification problem. In this scheme, the target values represented by an array of values betwen 0 and 1 (e.g., y=[0, 0, 1], y\\`=[0.1, 0.1, 0.9]))\n", 49 | "\\begin{align}\n", 50 | "L = \\sum y\\log y` \n", 51 | "\\end{align}\n", 52 | "\n", 53 | "\n", 54 | "\n", 55 | "## Back propagation\n", 56 | "\n", 57 | "$\n", 58 | "\\begin{align}\n", 59 | "%\\frac{\\partial L}{\\partial y} & = y-Y \\\\\n", 60 | "\\Delta_3 & = \\frac{\\partial L}{\\partial z3} = \\frac{\\partial L}{\\partial y`} \\frac{\\partial y`}{\\partial z_3} = y`-Y \\\\\n", 61 | "\\frac{\\partial L}{\\partial w_3}& = \\Delta_3 \\cdot h_2,~~~\n", 62 | "\\frac{\\partial L}{\\partial b_3} = \\Delta_3, ~~~ \n", 63 | "\\frac{\\partial L}{\\partial h_2} = \\Delta_3 \\cdot w_3 \\\\\n", 64 | "\\Delta_2 & = \\frac{\\partial L}{\\partial h_2} \\frac{\\partial h_2}{\\partial z_2} = \\Delta_3 \\cdot w_3 (1-h_2)h_2\\\\\n", 65 | "\\frac{\\partial L}{\\partial w_2} & = \\Delta_2 h_1,~~~\n", 66 | "\\frac{\\partial L}{\\partial b_2} = \\Delta_2 ~~~\n", 67 | "\\frac{\\partial L}{\\partial h_1} = \\Delta_3 \\cdot w_2\\\\\n", 68 | "\\Delta_1 & = \\frac{\\partial L}{\\partial h_1} \\frac{\\partial h_1}{\\partial z_1} = \\Delta_2 \\cdot w_2 (1-h_1)h_1\\\\\n", 69 | "\\frac{\\partial L}{\\partial w_2} & = \\Delta_1 \\cdot x,~~~\n", 70 | "\\frac{\\partial L}{\\partial b_2} = \\Delta_1 \\\\\n", 71 | "\\end{align}\n", 72 | "$\n", 73 | "\n" 74 | ] 75 | }, 76 | { 77 | "cell_type": "code", 78 | "execution_count": 1, 79 | "metadata": {}, 80 | "outputs": [], 81 | "source": [ 82 | "%matplotlib inline\n", 83 | "\n", 84 | "import numpy as np\n", 85 | "import sys\n", 86 | "import matplotlib.pyplot as plt\n", 87 | "\n", 88 | "class my_MLPClassifier(object):\n", 89 | " \"\"\"\n", 90 | " Basic MultiLayer Perceptron (MLP) neural network.\n", 91 | " Args:\n", 92 | " hidden layer: []\n", 93 | " max_iterations: []\n", 94 | " \"\"\"\n", 95 | " def __init__(self, hidden, max_iter, \n", 96 | " learning_rate=0.001, decay_rate=0.999, \n", 97 | " activation='sigmoid', loss='logloss'):\n", 98 | " \"\"\"\n", 99 | " :param hidden: number of hidden neurons\n", 100 | " :param iterations: how many epochs\n", 101 | " :param learning_rate: initial learning rate\n", 102 | " \"\"\"\n", 103 | " # initialize input parameters\n", 104 | " self.iterations = max_iter\n", 105 | " self.learning_rate = learning_rate\n", 106 | " self.decay_rate = decay_rate\n", 107 | " self.n_hid1, self.n_hid2 = hidden[0], hidden[1]\n", 108 | " self.activation_method = activation\n", 109 | " self.loss_method = loss\n", 110 | " \n", 111 | " def fit(self, x, y): \n", 112 | " \"\"\"\n", 113 | " input: [178, 13] = [example, wine features]\n", 114 | " output: [178, 3] = [example, class probabilities] \n", 115 | " \"\"\"\n", 116 | " # Initialize the weights and bias according to the input/target data\n", 117 | " dim_in, dim_out = x.shape[1], 3\n", 118 | " self.w1 = np.random.randn(dim_in, self.n_hid1) # [13,4] -- 52 weights \n", 119 | " self.w2 = np.random.randn(self.n_hid1, self.n_hid2) # [4,4] -- 16 weights\n", 120 | " self.w3 = np.random.randn(self.n_hid2, dim_out) # [4,3] -- 12 weights\n", 121 | " self.b1 = np.random.randn(1,self.n_hid1) # [1,4] -- 4 biases\n", 122 | " self.b2 = np.random.randn(1,self.n_hid2) # [1,4] -- 4 biases\n", 123 | " self.b3 = np.random.randn(1,dim_out) # [1,3] -- 3 bias\n", 124 | " loss_hist = [] # track loss for printing\n", 125 | " \n", 126 | " for i in range(self.iterations):\n", 127 | " # forward\n", 128 | " (h1,h2,y_) = self.forward(x)\n", 129 | " cost = self.loss_function(y_,y) \n", 130 | " loss_hist.append(cost)\n", 131 | " \n", 132 | " # backprop\n", 133 | " delta3 = (y_-y)\n", 134 | " gradw3 = np.dot(np.transpose(h2),delta3)\n", 135 | " gradb3 = np.sum(delta3, axis = 0)\n", 136 | " delta2 = np.dot(delta3, np.transpose(self.w3)) * self.grad_activation(h2)\n", 137 | " gradw2 = np.dot(np.transpose(h1),delta2)\n", 138 | " gradb2 = np.sum(delta2, axis=0) \n", 139 | " delta1 = np.dot(delta2, np.transpose(self.w2)) * self.grad_activation(h1)\n", 140 | " gradw1 = np.dot(np.transpose(x),delta1)\n", 141 | " gradb1 = np.sum(delta1, axis=0)\n", 142 | " \n", 143 | " # update parameters\n", 144 | " learning_rate = self.learning_rate * (self.decay_rate**i)\n", 145 | " self.w3 -= learning_rate*gradw3\n", 146 | " self.b3 -= learning_rate*gradb3\n", 147 | " self.w2 -= learning_rate*gradw2\n", 148 | " self.b2 -= learning_rate*gradb2\n", 149 | " self.w1 -= learning_rate*gradw1\n", 150 | " self.b1 -= learning_rate*gradb1\n", 151 | " if i%100==0 or i+1==self.iterations:\n", 152 | " print('activation function: {:s}, loss function: {:s} = {:8.3f}, iterations: {:d}, learning rate: {:6.4f}'\n", 153 | " .format(self.activation_method, self.loss_method, round(cost,3), i, learning_rate))\n", 154 | " self.weights = (self.w3, self.w2, self.w1)\n", 155 | " self.bias = (self.b3, self.b2, self.b1)\n", 156 | " \n", 157 | " # plot the training curve\n", 158 | " plt.title('training curve')\n", 159 | " plt.xlabel('epoch')\n", 160 | " plt.ylabel('loss')\n", 161 | " plt.plot(np.arange(0,self.iterations),loss_hist)\n", 162 | " plt.show()\n", 163 | " \n", 164 | " def loss_function(self,y_,y): \n", 165 | " m = len(y)\n", 166 | " if self.loss_method == 'logloss':\n", 167 | " y_ /= y_.sum(axis=1)[:, np.newaxis]\n", 168 | " return -1 * np.sum(y * np.log(y_))/len(y)\n", 169 | " else:\n", 170 | " raise NotImplementedError\n", 171 | " \n", 172 | " def hid_activation(self,x): \n", 173 | " if self.activation_method == 'sigmoid':\n", 174 | " return 1./(1+np.exp(-x))\n", 175 | " else:\n", 176 | " raise NotImplementedError\n", 177 | "\n", 178 | " def grad_activation(self,x):\n", 179 | " if self.activation_method == 'sigmoid': \n", 180 | " return x * (1-x)\n", 181 | " else:\n", 182 | " raise NotImplementedError\n", 183 | "\n", 184 | " def out_activation(self, x): \n", 185 | " if self.loss_method == 'logloss':\n", 186 | " return np.exp(x)/np.sum(np.exp(x),axis=1)[:, np.newaxis] \n", 187 | " else:\n", 188 | " raise NotImplementedError\n", 189 | " \n", 190 | " def forward(self,x):\n", 191 | " z1 = np.dot(x,self.w1)+self.b1\n", 192 | " h1 = self.hid_activation(z1)\n", 193 | " z2 = np.dot(h1,self.w2)+self.b2\n", 194 | " h2 = self.hid_activation(z2)\n", 195 | " z3 = np.dot(h2,self.w3)+self.b3\n", 196 | " y_ = self.out_activation(z3) \n", 197 | " return(h1,h2,y_)\n", 198 | " \n", 199 | " def predict(self, x):\n", 200 | " (h1, h2, y) = self.forward(x)\n", 201 | " y_ = np.zeros(y.shape[0],int) \n", 202 | " # array to reshape predictions to (178,)\n", 203 | " for i in range(len(y)):\n", 204 | " for j in range(len(y[i])):\n", 205 | " y[i,j] = round(y[i,j],0)\n", 206 | " y_[i] = np.argmax(y[i])\n", 207 | " return y_\n", 208 | "\n" 209 | ] 210 | }, 211 | { 212 | "cell_type": "code", 213 | "execution_count": 2, 214 | "metadata": {}, 215 | "outputs": [], 216 | "source": [ 217 | "## Obtain the data\n", 218 | "from sklearn.datasets import load_wine\n", 219 | "from sklearn.preprocessing import StandardScaler, OneHotEncoder\n", 220 | "data=load_wine()\n", 221 | "x, Y = data.data, data.target" 222 | ] 223 | }, 224 | { 225 | "cell_type": "markdown", 226 | "metadata": {}, 227 | "source": [ 228 | "## preprocess the data\n", 229 | "\n", 230 | "As usual, it is important to process the data as follows:\n", 231 | "- x, it is recommended to normalize x for NN before the fitting through the `StandardScaler` in sklearn. \n", 232 | "- Y, if it is a classification problem, we need to transform Y to a set of arrays with 0 or 1. For instance, there exist four classes (1, 2, 3, 4), we need to transform them to [1,0,0,0], [0,1,0,0], [0,0,1,0] and [0,0,0,1]. Fortunately, this can be done via `OneHotEncoder` in sklearn as well." 233 | ] 234 | }, 235 | { 236 | "cell_type": "code", 237 | "execution_count": 3, 238 | "metadata": {}, 239 | "outputs": [ 240 | { 241 | "name": "stdout", 242 | "output_type": "stream", 243 | "text": [ 244 | "[1.423e+01 1.710e+00 2.430e+00 1.560e+01 1.270e+02 2.800e+00 3.060e+00\n", 245 | " 2.800e-01 2.290e+00 5.640e+00 1.040e+00 3.920e+00 1.065e+03]\n", 246 | "[ 1.51861254 -0.5622498 0.23205254 -1.16959318 1.91390522 0.80899739\n", 247 | " 1.03481896 -0.65956311 1.22488398 0.25171685 0.36217728 1.84791957\n", 248 | " 1.01300893]\n", 249 | "0\n", 250 | "[1. 0. 0.]\n" 251 | ] 252 | }, 253 | { 254 | "name": "stderr", 255 | "output_type": "stream", 256 | "text": [ 257 | "/anaconda3/lib/python3.6/site-packages/sklearn/preprocessing/_encoders.py:363: FutureWarning: The handling of integer data will change in version 0.22. Currently, the categories are determined based on the range [0, max(values)], while in the future they will be determined based on the unique values.\n", 258 | "If you want the future behaviour and silence this warning, you can specify \"categories='auto'\".\n", 259 | "In case you used a LabelEncoder before this OneHotEncoder to convert the categories to integers, then you can now use the OneHotEncoder directly.\n", 260 | " warnings.warn(msg, FutureWarning)\n" 261 | ] 262 | } 263 | ], 264 | "source": [ 265 | "scaler = StandardScaler() \n", 266 | "scaler.fit(x) \n", 267 | "x0 = scaler.transform(x)\n", 268 | "Y0 = OneHotEncoder().fit_transform(np.expand_dims(Y, axis=1)).toarray()\n", 269 | "print(x[0])\n", 270 | "print(x0[0])\n", 271 | "print(Y[0])\n", 272 | "print(Y0[0])" 273 | ] 274 | }, 275 | { 276 | "cell_type": "code", 277 | "execution_count": 4, 278 | "metadata": { 279 | "scrolled": false 280 | }, 281 | "outputs": [ 282 | { 283 | "name": "stdout", 284 | "output_type": "stream", 285 | "text": [ 286 | "activation function: sigmoid, loss function: logloss = 1.447, iterations: 0, learning rate: 0.0100\n", 287 | "activation function: sigmoid, loss function: logloss = 0.045, iterations: 100, learning rate: 0.0090\n", 288 | "activation function: sigmoid, loss function: logloss = 0.019, iterations: 199, learning rate: 0.0082\n" 289 | ] 290 | }, 291 | { 292 | "data": { 293 | "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEWCAYAAACJ0YulAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4wLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvqOYd8AAAIABJREFUeJzt3XmYXGWd9vHvXdVLtk5n69DZIAkESAJhmZZhRBEvkUBgQB1QcBmdwWGcwRl9XUZ4dZSXcRa38XVhVHQQYRQUkREVDbIIIxqkWSUJgRCWhCSks++91W/+qNOdStPd6cQ+VdVd9+e6+qpTz3nq1K9PV/fd5zmbIgIzMzOATKkLMDOz8uFQMDOzbg4FMzPr5lAwM7NuDgUzM+vmUDAzs24OBasYkr4u6R8Hu6/ZcCKfp2BDgaTngfdGxF2lrsVsOPOWgg0LkqpKXUMxVdr3a8XjULCyJ+lG4HDgJ5J2SvoHSTMlhaRLJb0I3JP0vUXSeknbJN0vaX7Bcq6X9Olk+gxJayR9WNIGSesk/cUh9p0o6SeStkt6SNKnJf26n+/nNZJ+I2mrpNWS3pO0/0rSewv6vadwOcn3e7mkZ4BnkiGuz/dY9o8lfSiZnirpVkktkp6T9PeH9AOwiuJQsLIXEe8CXgT+NCLGRMRnC2a/DpgLLEye/xyYA0wGHgG+28+iG4F6YBpwKXCNpPGH0PcaYFfS593JV68kHZ7U+BWgATgReKyfGnt6E/DHwDzge8DbJClZ9njgLOBmSRngJ8DjSc1vAD4oaWGvSzVLOBRsqLsqInZFxB6AiLguInZERCtwFXCCpPo+XtsOXB0R7RFxB7ATOOZg+krKAn8GfCoidkfEMuA7/dT7DuCuiLgpWdamiDiYUPjXiNicfL//AwTw2mTehcBvI2It8CqgISKujoi2iFgFfBO4+CDeyyqQxyVtqFvdNZH8gf5n4CLy/4XnklmT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gPmSHga2kd/vAPnLGH89+aO/CviLpP1dwDckXZ0s46Iifhtmh8RXSTUbIEk7I2JMqeswS5OHj8zMrJu3FMzMrJu3FMzMrJtDwczMujkUzMysm0PBzMy6ORTMzKzb/wJBBADco85kjQAAAABJRU5ErkJggg==\n", 294 | "text/plain": [ 295 | "
" 296 | ] 297 | }, 298 | "metadata": { 299 | "needs_background": "light" 300 | }, 301 | "output_type": "display_data" 302 | } 303 | ], 304 | "source": [ 305 | "### mlp parameters\n", 306 | "my_mlp = my_MLPClassifier(hidden=[4,2], max_iter=200, learning_rate=0.01)\n", 307 | "my_mlp.fit(x0, Y0)" 308 | ] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "execution_count": 5, 313 | "metadata": {}, 314 | "outputs": [ 315 | { 316 | "name": "stdout", 317 | "output_type": "stream", 318 | "text": [ 319 | "178\n" 320 | ] 321 | } 322 | ], 323 | "source": [ 324 | "y_ = my_mlp.predict(x0)\n", 325 | "count = len(y_[y_==Y])\n", 326 | "print(count)" 327 | ] 328 | }, 329 | { 330 | "cell_type": "code", 331 | "execution_count": 6, 332 | "metadata": {}, 333 | "outputs": [ 334 | { 335 | "name": "stdout", 336 | "output_type": "stream", 337 | "text": [ 338 | "accuracy after 200 iterations is 100.00%\n" 339 | ] 340 | } 341 | ], 342 | "source": [ 343 | "print('accuracy after {:4d} iterations is {:6.2f}%'.format(my_mlp.iterations, 100*count/len(y_)))" 344 | ] 345 | } 346 | ], 347 | "metadata": { 348 | "kernelspec": { 349 | "display_name": "Python 3", 350 | "language": "python", 351 | "name": "python3" 352 | }, 353 | "language_info": { 354 | "codemirror_mode": { 355 | "name": "ipython", 356 | "version": 3 357 | }, 358 | "file_extension": ".py", 359 | "mimetype": "text/x-python", 360 | "name": "python", 361 | "nbconvert_exporter": "python", 362 | "pygments_lexer": "ipython3", 363 | "version": "3.6.8" 364 | } 365 | }, 366 | "nbformat": 4, 367 | "nbformat_minor": 2 368 | } 369 | -------------------------------------------------------------------------------- /Tutorials/ML/Readme.md: -------------------------------------------------------------------------------- 1 | # Machine Learning Lecture notes 2 | This repo is primarily designed for the introduction of various **machine learning methods** such as 3 | - neural network 4 | - support vector machine 5 | - decision tree 6 | - random forest 7 | 8 | and basic techniques used in data science 9 | - preprocessing 10 | - regularization 11 | 12 | and some others. 13 | 14 | In principle, we intend to review each method from three aspects 15 | - mathematic principle: fundamental concepts 16 | - pratical application: we will primarily use the modules based on scikit-learn 17 | - coding session: we will build a light version of code from the scratch to mimic the modules in scikit-learn. 18 | -------------------------------------------------------------------------------- /Tutorials/ML/img/MLP.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/Tutorials/ML/img/MLP.jpeg -------------------------------------------------------------------------------- /Tutorials/ML/img/neuron.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/Tutorials/ML/img/neuron.png -------------------------------------------------------------------------------- /Tutorials/ML/img/nn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/Tutorials/ML/img/nn.png -------------------------------------------------------------------------------- /Tutorials/README.md: -------------------------------------------------------------------------------- 1 | # Tutorials 2 | Some tutorials for internal use 3 | 4 | - VASP, a brief introduction of DFT and VASP, by Byungkyun Kang 5 | - MD\_LAMMPS, a brief introduction of MD and LAMMPS, by Pedro Santos 6 | - Machine Learning, a serious of ML notebooks, by Qiang Zhu 7 | - Convex\_hull, a pedagogical review of convex hull that is used in materials stability analysis, by Qiang Zhu 8 | 9 | -------------------------------------------------------------------------------- /Tutorials/VASP_lecture/readme.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Tutorials/VASP_lecture/vasp.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/Tutorials/VASP_lecture/vasp.pdf -------------------------------------------------------------------------------- /img/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/img/1.png -------------------------------------------------------------------------------- /img/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/img/2.png -------------------------------------------------------------------------------- /img/convex_hull_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/img/convex_hull_1.png -------------------------------------------------------------------------------- /img/convex_hull_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/img/convex_hull_2.png -------------------------------------------------------------------------------- /img/convex_hull_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/img/convex_hull_3.png -------------------------------------------------------------------------------- /img/convex_hull_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/img/convex_hull_4.png -------------------------------------------------------------------------------- /img/convex_hull_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/img/convex_hull_5.png -------------------------------------------------------------------------------- /img/convex_hull_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/img/convex_hull_6.png -------------------------------------------------------------------------------- /img/convex_hull_7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/img/convex_hull_7.png -------------------------------------------------------------------------------- /img/convex_hull_8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/img/convex_hull_8.png -------------------------------------------------------------------------------- /img/convex_hull_9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MaterSim/CMS/57a2be26702b3cb1fd353781900698078e465541/img/convex_hull_9.png -------------------------------------------------------------------------------- /misc/LR_order.py: -------------------------------------------------------------------------------- 1 | from ase import Atoms 2 | from ase import io 3 | import pyxtal 4 | import numpy as np 5 | import copy 6 | from scipy.signal import savgol_filter 7 | import scipy.signal as sig 8 | import matplotlib.pyplot as plt 9 | import pandas as pd 10 | import json 11 | 12 | 13 | class LR_order: 14 | def __init__(self,poscars,ele,plane_density=5,load=None): 15 | """ 16 | Compares long range order preservation for all crystallographic planes in a series of structures 17 | connecting a crystal to its amorphous phase. 18 | 19 | Args: 20 | 21 | poscars: list of filenames to poscar files 22 | ele: element used to track order 23 | plane_density: calculates order for all planes with indicies less than value 24 | load: dictionary object created from previous LR_order calculation using save_p function. 25 | """ 26 | 27 | self.structures=[] 28 | for x in poscars: 29 | s=pyxtal.pyxtal() 30 | s.from_seed(x) 31 | self.structures.append(s) 32 | 33 | if load is not None: 34 | self.planes=np.array(load['planes']) 35 | self.struc_projections=np.array(load['struc_projections']) 36 | self.projection_bins=np.array(load['projection_bins']) 37 | print(len(self.planes)) 38 | 39 | else: 40 | #finds all planes for order calculation 41 | sample=io.read(poscars[0]) 42 | self.planes=[x for x in pyxtal.XRD(sample).hkl_list if np.all(np.abs(x)<=plane_density)] 43 | self.point_projections(ele=ele) 44 | 45 | 46 | #q is order. Lower value is more order. Index is same as planes index. 47 | self.q=[] 48 | scatter=[] 49 | for p in self.projection_bins: 50 | r,zz=self.quantify_order(p) 51 | self.q.append(np.round(r,10)) 52 | scatter.append(zz) 53 | 54 | 55 | 56 | 57 | # argsortedq=np.argsort(self.q) 58 | # for j,i in enumerate(argsortedq[1:]): 59 | # if self.q[argsortedq[j]]==self.q[argsortedq[j-1]]: 60 | # continue 61 | # fig,ax=plt.subplots(nrows=1,ncols=2,figsize=(13,5)) 62 | # ax[0].hist(self.projection_bins[i],50) 63 | # ax[0].set_title(str(self.planes[i])+' '+str(self.q[i])+' '+str(i)) 64 | # ax[1].scatter(scatter[i][0],scatter[i][1],color='red') 65 | # ax[1].plot(scatter[i][2][:-1],scatter[i][3]) 66 | # plt.show() 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | def point_projections(self,ele): 75 | """ 76 | Projects the location of atoms of ele in the structure onto the planes in self.planes. 77 | 78 | Returns: 79 | self.struc_projection: the atom projections distances for each structure, seperated by structure 80 | self.projection_bins: the atom projections distances for every structure, seperated by planes. 81 | """ 82 | points=[] 83 | for struc in self.structures: 84 | points_=[] 85 | for i,plane in enumerate(self.planes): 86 | points_.append(sorted(self.projector(struc,plane,ele))) 87 | points.append(points_) 88 | 89 | zss=[] 90 | for i,y in enumerate(self.planes): 91 | zss.append([x[i] for x in points]) 92 | 93 | ###Broken poscarfile correct? 94 | for i,x in enumerate(zss): 95 | for j,y in enumerate(zss[i]): 96 | if len(y)==1: 97 | zss[i].pop(j) 98 | 99 | for i,p in enumerate(zss): 100 | zss[i]=self.shifted_c(p) 101 | 102 | pss=[] 103 | for v in zss: 104 | pzz=[] 105 | for w in v: 106 | pzz.extend(w) 107 | pss.append(pzz) 108 | 109 | self.struc_projections=zss 110 | self.projection_bins=pss 111 | 112 | def shifted_c(self,points): 113 | """ 114 | Shifts all the projected points to be centered at the middle of the average range. Helps with comparisons. 115 | """ 116 | a=np.average([x[0] for x in points]) 117 | b=np.average([x[-1] for x in points]) 118 | c=(a+b)/2 119 | for i in range(1,len(points)): 120 | shift=((points[i][-1]+points[i][0])/2)-c 121 | points[i]=points[i]-shift 122 | return points 123 | 124 | def projector(self,struc,plane,specie): 125 | """ 126 | Finds distances of atoms projected along crystal plane 127 | """ 128 | 129 | total=[] 130 | mat=struc.lattice.matrix 131 | unit=np.array(plane)/np.linalg.norm(plane) #create unit vector for projection. 132 | r=[np.linalg.norm(np.dot(np.dot(site.position,unit),mat)) for site in struc.atom_sites if site.specie==specie] 133 | return r 134 | 135 | def quantify_order(self,p): 136 | """ 137 | Quantifies the order of particular plane. Uses a histogram of the projected points. Peak finder and peak width 138 | calculator is used to quantify relative atom distance consistency between all the structures. 139 | 140 | Returns: 141 | width of maximum width peak 142 | x,y coordinates of found peaks 143 | x,y coordinates of smoothing function 144 | """ 145 | 146 | y,x=np.histogram(p,bins=50,density=True) 147 | yhat=savgol_filter(y,19,12)#can tune this value 148 | zz,props=sig.find_peaks(yhat,width=2.4) 149 | yy=[yhat[v] for v in list(zz)] 150 | xx=[x[v] for v in list(zz)] 151 | return max(props['widths']),[xx,yy,x,yhat] 152 | 153 | def plotting_data(self,filename='plot_data.csv'): 154 | """ 155 | Prints data to be used in plotting function 156 | """ 157 | d={'h':[x[0] for x in self.planes], 158 | 'k':[x[1] for x in self.planes], 159 | 'l':[x[2] for x in self.planes], 160 | 'I':[x for x in self.q]} 161 | df=pd.DataFrame.from_dict(d) 162 | df.to_csv(filename) 163 | 164 | 165 | # def save_p(self,filename='load_data.csv'): 166 | # weith open( 167 | # d={'planes': self.planes, 168 | # 'struc_projections': self.struc_projections, 169 | # 'projection_bins': self.projection_bins} 170 | # df=pd.DataFrame.from_dict(d) 171 | # df.to_csv(filename) 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | if __name__ == "__main__": 185 | filenames=['S812/POSCAR.'+str(x) for x in range(1,813)] 186 | # df=read.csv('data.csv') 187 | o=LR_order(filenames,ele='Al',load=None) 188 | o.plotting_data(filename='plot_data.csv') 189 | # o.save_p() 190 | 191 | -------------------------------------------------------------------------------- /misc/Order_plot.py: -------------------------------------------------------------------------------- 1 | from plotly.figure_factory import create_trisurf 2 | from colorsys import hsv_to_rgb 3 | import pandas as pd 4 | import plotly.graph_objects as go 5 | import numpy as np 6 | from scipy.spatial import Delaunay 7 | import matplotlib.pyplot as plt 8 | 9 | 10 | class Order_plot(): 11 | 12 | def __init__(self, hkl,I,c1=1.2,c2=15): 13 | """ 14 | Plots the data from LR_order 15 | Args: 16 | hkl: list of miller planes 17 | I: intensities from LR_order 18 | c1: controls relative peak intensities. Higher value exaggerates highest peaks more. 19 | c2: controls sphere size relative to peak heights. Higher value makes peaks smaller relative height. 20 | """ 21 | 22 | #Load in Data 23 | h=np.array([x[0] for x in hkl]) 24 | k=np.array([x[1] for x in hkl]) 25 | l=np.array([x[2] for x in hkl]) 26 | I=np.array(I) 27 | 28 | #Prep Intensities for density calculation 29 | I=np.array([(1./x)**c1 for x in I]) 30 | I=I/np.max(I) 31 | 32 | 33 | 34 | sigma, n = 0.2, 20000 35 | xyzs = self.fibonacci_sphere(n) 36 | grids = np.zeros([n, 3]) 37 | grids[:, :2] = self.xyz2sph(xyzs) 38 | pts = [] 39 | for i in range(len(h)): 40 | p, r = self.hkl2tp(h[i], k[i], l[i]) 41 | pts.append([p, r, I[i]]) 42 | pts = np.array(pts) 43 | vals = self.calculate_density(pts, xyzs, sigma=sigma) 44 | 45 | 46 | #Prep heights for sphere scaling 47 | valss=(vals+c2) 48 | valss/=valss.max() 49 | for i,x in enumerate(valss): 50 | xyzs[i]*=np.abs(x) 51 | 52 | phi=[] 53 | rho=[] 54 | for row in xyzs: 55 | r,p=self.hkl2tp(row[0],row[1],row[2]) 56 | phi.append(p) 57 | rho.append(r) 58 | phi=np.array(phi) 59 | rho=np.array(rho) 60 | x=xyzs[:,0] 61 | y=xyzs[:,1] 62 | z=xyzs[:,2] 63 | 64 | self.x=x 65 | self.y=y 66 | self.z=z 67 | 68 | 69 | points2D=np.vstack([phi,rho]).T 70 | tri=Delaunay(points2D) 71 | simplices=tri.simplices 72 | trisurf=create_trisurf(x=x,y=y,z=z,colormap='Jet', simplices=simplices,plot_edges=False,color_func=self.color_func,show_colorbar=False) 73 | 74 | self.colorscale = [ 75 | [0, "rgb(84,48,5)"], 76 | [1, "rgb(84,48,5)"], 77 | ] 78 | 79 | layout = go.Layout(scene=dict(aspectmode='data',annotations=self.get_axis_names())) 80 | fig=go.Figure(data=trisurf, layout=layout) 81 | fig.add_trace(go.Scatter3d(x = [1.1,0,0], y = [0,1.1,0], z=[0,0,1.1], mode="text", text = ['a','b','c'])) 82 | self.add_axis_arrows(fig) 83 | fig.update_scenes(camera_projection_type='orthographic') 84 | fig.show() 85 | 86 | 87 | 88 | 89 | 90 | def color_func(self,x,y,z): 91 | """ 92 | Assigns color to distance 93 | """ 94 | mag=np.sqrt(x**2 + y**2 + z**2) 95 | return np.floor(mag*255.9999) 96 | 97 | def calculate_density(self,pts, xyzs, sigma=0.01): 98 | """ 99 | calculate the projected order density on the unit sphere 100 | uses gaussain distrbution to smooth points. 101 | """ 102 | vals = np.zeros(len(xyzs)) 103 | pi = np.pi 104 | for pt in pts: 105 | t0, p0, h = pt 106 | x0, y0, z0 = np.sin(t0)*np.cos(p0), np.sin(t0)*np.sin(p0), np.cos(t0) 107 | dst = np.linalg.norm(xyzs - np.array([x0, y0, z0]), axis=1) 108 | vals += h*np.exp(-(dst**2/(2.0*sigma**2))) 109 | return vals 110 | 111 | def hkl2tp(self,h, k, l): 112 | """ 113 | convert hkl to theta and phi 114 | """ 115 | mp = [h,k,l] 116 | r = np.linalg.norm(mp) 117 | 118 | theta = np.arctan2(mp[1],mp[0]) 119 | phi = np.arccos(mp[2]/r) 120 | 121 | #return theta, phi 122 | return phi, theta 123 | 124 | def fibonacci_sphere(self,samples=1000): 125 | """ 126 | Sampling the sphere grids 127 | 128 | Args: 129 | samples: number of pts to generate 130 | 131 | Returns: 132 | 3D points array in Cartesian coordinates 133 | """ 134 | points = [] 135 | phi = np.pi * (3. - np.sqrt(5.)) # golden angle in radians 136 | for i in range(samples): 137 | y = 1 - (i / float(samples - 1)) * 2 # y goes from 1 to -1 138 | radius = np.sqrt(1 - y * y) # radius at y 139 | theta = phi * i # golden angle increment 140 | x = np.cos(theta) * radius 141 | z = np.sin(theta) * radius 142 | points.append((x, y, z)) 143 | 144 | return np.array(points) 145 | 146 | 147 | def xyz2sph(self,xyzs, radian=True): 148 | """ 149 | convert the vectors (x, y, z) to the sphere representation (theta, phi) 150 | 151 | Args: 152 | xyzs: 3D xyz coordinates 153 | radian: return in radian (otherwise degree) 154 | """ 155 | pts = np.zeros([len(xyzs), 2]) 156 | for i, r_vec in enumerate(xyzs): 157 | r_mag = np.linalg.norm(r_vec) 158 | theta0 = np.arccos(r_vec[2]/r_mag) 159 | if abs((r_vec[2] / r_mag) - 1.0) < 10.**(-8.): 160 | theta0 = 0.0 161 | elif abs((r_vec[2] / r_mag) + 1.0) < 10.**(-8.): 162 | theta0 = np.pi 163 | 164 | if r_vec[0] < 0.: 165 | phi0 = np.pi + np.arctan(r_vec[1] / r_vec[0]) 166 | elif 0. < r_vec[0] and r_vec[1] < 0.: 167 | phi0 = 2 * np.pi + np.arctan(r_vec[1] / r_vec[0]) 168 | elif 0. < r_vec[0] and 0. <= r_vec[1]: 169 | phi0 = np.arctan(r_vec[1] / r_vec[0]) 170 | elif r_vec[0] == 0. and 0. < r_vec[1]: 171 | phi0 = 0.5 * np.pi 172 | elif r_vec[0] == 0. and r_vec[1] < 0.: 173 | phi0 = 1.5 * np.pi 174 | else: 175 | phi0 = 0. 176 | pts[i, :] = [theta0, phi0] 177 | if not radian: 178 | pts = np.degree(pts) 179 | 180 | return pts 181 | 182 | 183 | 184 | def get_arrow(self,axisname="x"): 185 | """ 186 | Creates arrow object to plot axis lines 187 | """ 188 | 189 | 190 | body = go.Scatter3d( 191 | marker=dict(size=1, color=self.colorscale[0][1]), 192 | line=dict(color=self.colorscale[0][1], width=3), 193 | showlegend=False, # hide the legend 194 | ) 195 | 196 | head = go.Cone( 197 | sizeref=0.1, 198 | autocolorscale=None, 199 | colorscale=self.colorscale, 200 | showscale=False, # disable additional colorscale for arrowheads 201 | hovertext=axisname, 202 | ) 203 | for ax, direction in zip(("x", "y", "z"), ("u", "v", "w")): 204 | if ax == axisname: 205 | body[ax] = -1,1 206 | head[ax] = [1] 207 | head[direction] = [1] 208 | else: 209 | body[ax] = 0,0 210 | head[ax] = [0] 211 | head[direction] = [0] 212 | 213 | return [body, head] 214 | 215 | 216 | def add_axis_arrows(self,fig): 217 | for ax in ("x", "y", "z"): 218 | for item in self.get_arrow(ax): 219 | fig.add_trace(item) 220 | 221 | def get_annotation_for_ax(self,ax): 222 | """ 223 | plots abc axis labels 224 | """ 225 | d = dict(showarrow=False, text=ax, xanchor="left", font=dict(color="#1f1f1f")) 226 | 227 | if ax == "a": 228 | d["x"] = 1.1 229 | d["y"] = 0 230 | d["z"] = 0 231 | elif ax == "b": 232 | d["x"] = 0 233 | d["y"] = 1.1 234 | d["z"] = 0 235 | else: 236 | d["x"] = 0 237 | d["y"] = 0 238 | d["z"] = 1.1 239 | 240 | if ax in {"a", "b"}: 241 | d["xshift"] = 15 242 | 243 | return d 244 | 245 | 246 | def get_axis_names(self): 247 | return [self.get_annotation_for_ax(ax) for ax in ("a", "b", "c")] 248 | 249 | def plot_cross_sections(self): 250 | """ 251 | Plots the axis plane cross sections of the plot 3D visualization 252 | Uses scattering of points under a limit as fibonacci sphere doesn't points distributed in a plane. 253 | """ 254 | x=self.x 255 | y=self.y 256 | z=self.z 257 | 258 | e=2e-2 259 | xy_a=[x_ for i,x_ in enumerate(x) if np.abs(z[i])