This repository has been archived by the owner on Dec 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ESPInterfaces.py
3060 lines (3001 loc) · 129 KB
/
ESPInterfaces.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright 2010 Torbjorn Bjorkman
# This file is part of cif2cell
#
# cif2cell is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cif2cell is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cif2cell. If not, see <http://www.gnu.org/licenses/>.
#
#******************************************************************************************
# Description: Interfaces for a number of electronic structure programs. Currently only
# reads CIF and outputs to the ESP's. Supported programs are: ABINIT, CASTEP,
# CPMD, Crystal09, DFTB+, Elk, EMTO, Exciting, Fleur, Hutsepot, NCOL, Quantum Espresso,
# RSPt, Siesta, VASP, xyz
#
# Author: Torbjorn Bjorkman, torbjorn.bjorkman(at)aalto.fi
# Affiliation: COMP, Aaalto University School of Science,
# Department of Applied Physics, Espoo, Finland
#******************************************************************************************
import copy
import os
import math
import string
from utils import *
from elementdata import *
from uctools import *
from re import search
################################################################################################
ed = ElementData()
suspiciouslist = set(["Cr", "Mn", "Fe", "Co", "Ni",
"Ce","Pr","Nd","Pm","Sm","Eu",
"Gd","Tb","Dy","Ho","Er","Tm",
"Th","Pa","U","Np","Pu"])
initialmoments = {"Cr" : 3, "Mn" : 3, "Fe" : 3, "Co" : 3, "Ni" : 1,
"Ce" : 1, "Pr" : 2, "Nd" : 3, "Pm" : 4, "Sm" : 5, "Eu" : 6,
"Gd" : 7, "Tb" : 8, "Dy" : 9, "Ho" : 10, "Er" : 11, "Tm" : 12,
"Th" : 1, "Pa" : 2, "U" : 3, "Np" : 4, "Pu" : 5 }
################################################################################################
class GeometryOutputFile:
"""
Parent class for electronic struture code files generated from geometrical information.
A CrystalStructure object and a documentation string are required input.
"""
def __init__(self, crystalstructure, string):
self.cell = crystalstructure
self.docstring = string
################################################################################################
# HUTSEPOT FILE
class HUTSEPOTFile(GeometryOutputFile):
"""
Class for storing the geometrical data needed for outputting a hutsepot input file
and the method __str__ that outputs the contents of the file as a string.
"""
def __init__(self,crystalstructure,string):
GeometryOutputFile.__init__(self,crystalstructure,string)
# Document string on first line after '//'
self.programdoc = string.rstrip("\n")
# set up species list
tmp = set([])
for a in self.cell.atomdata:
for b in a:
tmp.add(b.spcstring())
self.species = list(tmp)
# make sure the docstring goes on one line
self.cell.newunit("bohr")
def __str__(self):
streck="-------------------------------------------------------------------------------"
filestring = streck+"\n"
filestring += "------------------------- Generated by cif2cell -------------------------------\n"
filestring = streck+"\n"
t = self.cell.lengthscale
filestring += "3D unit cell alat=%18.12f blat=%18.12f clat=%18.12f\n"%(t,t,t)
filestring += " rb="+str(self.cell.latticevectors[0].scalmult(t))+"ascale=1.0\n"
filestring += " "+str(self.cell.latticevectors[1].scalmult(t))+"bscale=1.0\n"
filestring += " "+str(self.cell.latticevectors[2].scalmult(t))+"cscale=1.0\n"
# positions
filestring += "-------------------------------------------------------------------------------\n"
filestring += "------------------------------- atomic positions ------------------------------\n"
filestring += "-------------------------------------------------------------------------------\n"
positionstring = ""
species = 0
atom = 0
for sp in self.species:
nr = 0
species += 1
for a in self.cell.atomdata:
for b in a:
if b.spcstring() == sp:
atom += 1
nr += 1
p = Vector(mvmult3(self.cell.latticevectors,b.position.scalmult(self.cell.lengthscale)))
positionstring += str(species)+"."+b.spcstring()+"_"+str(nr)+" type=%i"%(atom)+" nat=60 tau="+str(p)
positionstring += "\n"
filestring += positionstring
filestring += "-------------------------------------------------------------------------------\n"
filestring += "---------------------------- atomic configurations ----------------------------\n"
filestring += "-------------------------------------------------------------------------------\n"
species = 0
for sp in self.species:
species += 1
filestring += str(species)+". "+ed.hutsepotelements[sp]+"\n"
filestring += "-------------------------------------------------------------------------------\n"
filestring += "------------------------------- atomic options --------------------------------\n"
filestring += "-------------------------------------------------------------------------------\n"
species = 0
atom = 0
for sp in self.species:
species += 1
for a in self.cell.atomdata:
for b in a:
if b.spcstring() == sp:
atom += 1
filestring += str(species)+". atom="+sp+" type="+str(atom)
filestring += " fix=F lmax=3 lmaxv=0 conc=1.0 mtz=T sort="+str(atom)+"\n"
filestring += "-------------------------------------------------------------------------------\n"
filestring += "--------------------------------- potentials ----------------------------------\n"
filestring += "-------------------------------------------------------------------------------\n"
species = 0
atom = 0
for sp in self.species:
species += 1
nr = 0
for a in self.cell.atomdata:
for b in a:
if b.spcstring() == sp:
atom += 1
nr += 1
filestring += str(species)+". type="+str(atom)
filestring += " np=1001 r1=1.0E-05 rnp=-2 pfile="+sp+str(nr)+".pot\n"
filestring += "-------------------------------------------------------------------------------\n"
return filestring
################################################################################################
# ASE FILE
class ASEFile(GeometryOutputFile):
"""
Class for storing the geometrical data needed for outputting data for ASE
and the method __str__ that outputs the contents of the file as a string of
python code.
"""
def __init__(self,crystalstructure,docstring):
GeometryOutputFile.__init__(self,crystalstructure,docstring)
# Variables
self.cartesian = True # Cartesian coordinates?
# Make sure the docstring has comment form
self.docstring = self.docstring.rstrip("\n")
tmpstrings = self.docstring.split("\n")
self.docstring = ""
for string in tmpstrings:
string = string.lstrip("#")
string = "#"+string+"\n"
self.docstring += string
# set up species list
tmp = set([])
for a in self.cell.atomdata:
for b in a:
tmp.add(b.spcstring())
self.species = list(tmp)
def __str__(self):
filestring = "from ase import *\n\n"
# Cartesian or lattice coordinates?
if self.cartesian:
transmtx = []
for i in range(3):
transmtx.append([])
for j in range(3):
transmtx[i].append(self.cell.latticevectors[i][j] * self.cell.lengthscale)
else:
transmtx = [[1,0,0],[0,1,0],[0,0,1]]
# positions and number of species
nspcs = []
positionstring = ""
for sp in self.species:
nsp = 0
for a in self.cell.atomdata:
for b in a:
if b.spcstring() == sp:
nsp += 1
p = Vector(mvmult3(transmtx,b.position))
positionstring += "%11f, %11f, %11f),\n ("%(p[0],p[1],p[2])
nspcs.append(nsp)
positionstring = positionstring.rstrip("\n (,")+"],\n"
# Atoms object
filestring += "atoms = Atoms("
# Species
for i in range(len(self.species)):
filestring += "['"+self.species[i]+"' for i in range("+str(nspcs[i])+")]+"
filestring = filestring.rstrip("+")+",\n"
# Positions
filestring += " [("
filestring += positionstring
# Boundary conditions
filestring += " pbc = (True,True,True))\n"
# Set lattice vectors
filestring += "atoms.set_cell([["
for i in range(3):
for j in range(3):
filestring += "%12f, "%(self.cell.latticevectors[i][j]*self.cell.lengthscale)
filestring = filestring.rstrip(", ")+"],\n ["
filestring = filestring.rstrip(",[ ]\n")+"]],\n"
filestring += " scale_atoms = %s)\n"%str(not self.cartesian)
return filestring
################################################################################################
# CFG FILE
class CFGFile(GeometryOutputFile):
"""
Class for storing the geometrical data needed for outputting a .cfg file
and the method __str__ that outputs the contents of the .coo file as a string.
"""
def __init__(self,crystalstructure,string):
GeometryOutputFile.__init__(self,crystalstructure,string)
# Make sure the docstring has comment form
self.docstring = self.docstring.rstrip("\n")
tmpstrings = self.docstring.split("\n")
self.docstring = ""
for string in tmpstrings:
string = string.lstrip("#")
string = "#"+string+"\n"
self.docstring += string
def __str__(self):
# Set up atom list for printing.
tmplist = list(self.cell.atomset)
atomlist = []
for a in tmplist:
if a.alloy():
for sp,occ in a.species.iteritems():
atomlist.append(AtomSite(position=a.position,species={sp : occ},charges={sp : a.charges[sp]}))
else:
atomlist.append(a)
atomlist.sort(key = lambda x: max([ed.elementnr[sp] for sp in x.species]),reverse=True)
prevsp = ""
natoms = len(atomlist)
# Make string
filestring = self.docstring
filestring += "Number of particles = %i \n"%(natoms)
filestring += "A = 1.0 Angstrom\n"
filestring += "H0(1,1) = %f A\n"%(self.cell.lengthscale*self.cell.latticevectors[0][0])
filestring += "H0(1,2) = %f A\n"%(self.cell.lengthscale*self.cell.latticevectors[0][1])
filestring += "H0(1,3) = %f A\n"%(self.cell.lengthscale*self.cell.latticevectors[0][2])
filestring += "H0(2,1) = %f A\n"%(self.cell.lengthscale*self.cell.latticevectors[1][0])
filestring += "H0(2,2) = %f A\n"%(self.cell.lengthscale*self.cell.latticevectors[1][1])
filestring += "H0(2,3) = %f A\n"%(self.cell.lengthscale*self.cell.latticevectors[1][2])
filestring += "H0(3,1) = %f A\n"%(self.cell.lengthscale*self.cell.latticevectors[2][0])
filestring += "H0(3,2) = %f A\n"%(self.cell.lengthscale*self.cell.latticevectors[2][1])
filestring += "H0(3,3) = %f A\n"%(self.cell.lengthscale*self.cell.latticevectors[2][2])
filestring += ".NO_VELOCITY.\n"
## # Cut the fancy stuff for now, stick with just the positions
## filestring += "entry_count = 3\n"
filestring += "entry_count = 6\n"
for a in atomlist:
for sp,occ in a.species.iteritems():
if prevsp != sp:
filestring += "%i\n"%(int(round(ed.elementweight[sp])))
filestring += sp+"\n"
prevsp = sp
DW = 0.45*ed.elementnr['Si']/ed.elementnr[sp] # Debye-Waller factor, QSTEM prescription
filestring += str(a.position)+" %f "%(DW)+" %f "%(occ)+" %f\n"%(a.charges[sp])
## filestring += str(a.position)+"\n"
return filestring
################################################################################################
# COO FILE
class COOFile(GeometryOutputFile):
"""
Class for storing the geometrical data needed for outputting a .coo file
and the method __str__ that outputs the contents of the .coo file as a string.
"""
def __init__(self,crystalstructure,string):
GeometryOutputFile.__init__(self,crystalstructure,string)
# Document string on first line after '//'
self.programdoc = string.rstrip("\n")
def __str__(self):
filestring = "//"+self.programdoc+"\n"
a = self.cell.latticevectors[0].length()*self.cell.lengthscale
b = self.cell.latticevectors[1].length()*self.cell.lengthscale
c = self.cell.latticevectors[2].length()*self.cell.lengthscale
alpha = abs(self.cell.latticevectors[1].angle(self.cell.latticevectors[2]))*180/pi
beta = abs(self.cell.latticevectors[2].angle(self.cell.latticevectors[0]))*180/pi
gamma = abs(self.cell.latticevectors[0].angle(self.cell.latticevectors[1]))*180/pi
filestring += " %10.7f %10.7f %10.7f"%(a,b,c)
filestring += " %10.7f %10.7f %10.7f %i\n"%(alpha,beta,gamma,len(self.cell.atomset))
for a in self.cell.atomdata:
for b in a:
filestring += str(b.position)+" %3i 0.500 0.000 1.000\n"%(ed.elementnr[b.spcstring()])
return filestring
################################################################################################
# XYZ FILE
class LAMMPSFile(GeometryOutputFile):
"""
Class for storing the geometrical data needed for outputting an .data LAMMPS file
and the method __str__ that outputs the contents of the .data file as a string.
"""
def __init__(self,crystalstructure,string):
GeometryOutputFile.__init__(self,crystalstructure,string)
# To be put on the second line
self.programdoc = ""
def __str__(self):
filestring = ""
filestring += "#"+self.docstring+"\n\n"
filestring += "%i atoms\n" % sum([len(v) for v in self.cell.atomdata])
atomTypes = {}
nextAtomTypeId = 1
for a in self.cell.atomdata:
for b in a:
atomType = str(b).split()[0]
if not atomType in atomTypes:
atomTypes[atomType] = nextAtomTypeId
nextAtomTypeId += 1
filestring += "%i atom types\n\n" % len(atomTypes)
if self.cell.latticevectors[0][1]!=0:
theta = math.atan2(-self.cell.latticevectors[0][1], self.cell.latticevectors[0][0])
c = cos(theta)
s = sin(theta)
R = LatticeMatrix([[c, s, 0],
[-s, c, 0],
[0, 0, 1]])
self.cell.latticevectors[0] = Vector(mvmult3(R,self.cell.latticevectors[0]))
self.cell.latticevectors[1] = Vector(mvmult3(R,self.cell.latticevectors[1]))
self.cell.latticevectors[2] = Vector(mvmult3(R,self.cell.latticevectors[2]))
if self.cell.latticevectors[0][2]!=0:
theta = math.atan2(-self.cell.latticevectors[0][2], self.cell.latticevectors[0][0])
c = cos(theta)
s = sin(theta)
R = LatticeMatrix([[c, s, 0],
[0, 1, 0],
[-s, c, 0]])
self.cell.latticevectors[0] = Vector(mvmult3(R,self.cell.latticevectors[0]))
self.cell.latticevectors[1] = Vector(mvmult3(R,self.cell.latticevectors[1]))
self.cell.latticevectors[2] = Vector(mvmult3(R,self.cell.latticevectors[2]))
if self.cell.latticevectors[1][2]!=0:
theta = math.atan2(-self.cell.latticevectors[1][2], self.cell.latticevectors[1][1])
c = cos(theta)
s = sin(theta)
R = LatticeMatrix([[1, 0, 0],
[0, c, s],
[0, -s, c]])
self.cell.latticevectors[0] = Vector(mvmult3(R,self.cell.latticevectors[0]))
self.cell.latticevectors[1] = Vector(mvmult3(R,self.cell.latticevectors[1]))
self.cell.latticevectors[2] = Vector(mvmult3(R,self.cell.latticevectors[2]))
if self.cell.latticevectors[0][1]!=0 or self.cell.latticevectors[0][2] != 0 or self.cell.latticevectors[1][2]!=0 or self.cell.latticevectors[0][0] <= 0 or self.cell.latticevectors[1][1] <= 0 or self.cell.latticevectors[2][2] <= 0:
print "Error in triclinic box. Vectors should follow these rules: http://lammps.sandia.gov/doc/Section_howto.html#howto-12"
print "Ideally, this program should solve this, but it doesn't yet. You need to fix it."
exit()
xy = self.cell.lengthscale*self.cell.latticevectors[1][0]
xz = self.cell.lengthscale*self.cell.latticevectors[2][0]
yz = self.cell.lengthscale*self.cell.latticevectors[2][1]
a = self.cell.latticevectors[0][0]*self.cell.lengthscale
b = self.cell.latticevectors[1][1]*self.cell.lengthscale
c = self.cell.latticevectors[2][2]*self.cell.lengthscale
filestring += "0.0 %f xlo xhi\n" % a
filestring += "0.0 %f ylo yhi\n" % b
filestring += "0.0 %f zlo zhi\n" % c
if xy!=0 or xz !=0 or yz != 0:
filestring += str(xy) + " " + str(xz) + " " + str(yz) + " xy xz yz\n"
filestring += "\n"
filestring += "Atoms\n\n"
nextAtomId = 1
#for b in [a for a in self.cell.atomdata]:
#print str(b).split()[0]
#atomTypes str(b).split()[0]
lv = []
for i in range(3):
lv.append([])
for j in range(3):
lv[i].append(self.cell.lengthscale*self.cell.latticevectors[i][j])
for a in self.cell.atomdata:
for b in a:
t = Vector(mvmult3(lv,b.position))
atomType = str(b).split()[0]
atomTypeId = atomTypes[atomType]
filestring += str(nextAtomId)+" "+str(atomTypeId)+" "+str(t)+"\n"
nextAtomId += 1
return filestring
################################################################################################
# XYZ FILE
class XYZFile(GeometryOutputFile):
"""
Class for storing the geometrical data needed for outputting an .xyz file
and the method __str__ that outputs the contents of the .xyz file as a string.
"""
def __init__(self,crystalstructure,string):
GeometryOutputFile.__init__(self,crystalstructure,string)
# To be put on the second line
self.programdoc = ""
def __str__(self):
filestring = ""
filestring += "%i \n"%sum([len(v) for v in self.cell.atomdata])
filestring += self.docstring+"\n"
lv = []
for i in range(3):
lv.append([])
for j in range(3):
lv[i].append(self.cell.lengthscale*self.cell.latticevectors[i][j])
for a in self.cell.atomdata:
for b in a:
t = Vector(mvmult3(lv,b.position))
filestring += str(b).split()[0]+" "+str(t)+"\n"
return filestring
################################################################################################
# NCOL FILES
class OldNCOLFile(GeometryOutputFile):
"""
Class for storing the geometrical data needed in a [filename].dat file for the ncol program
and the method __str__ that outputs the contents of the .dat file as a string.
"""
def __init__(self,crystalstructure,string):
GeometryOutputFile.__init__(self,crystalstructure,string)
# Set atomic units for length scale
self.jobnam = "default"
self.bstrjobnam = "default"
# To be put on the first line
self.programdoc = ""
# Set atomic units for length scale
self.cell.newunit("bohr")
def __str__(self):
# Element data
ed = ElementData()
# l quantum number setup (same as from bstr)
l = { "s" : 2, "p" : 2, "d" : 3, "f" : 4 }
filestring = ""
tmpstring = "BULK IDSYST= 7 SCRATCH=R"
tmpstring = tmpstring.ljust(25)+" "+deletenewline(self.programdoc,replace=" ")+"\n"
filestring += tmpstring
tmpstring = "JOBNAM...="+self.jobnam.ljust(10)+" MSGL.= 1 BSAVE..=N COLD...=Y DOS...=N SPO...=N ISM...=G RCLCR...=Y\n"
filestring += tmpstring
filestring += "FOR001=./"+self.bstrjobnam+".tfm\n"
filestring += "FOR002=\n"
filestring += "FOR003=\n"
filestring += "FOR004=\n"
filestring += "FOR006=\n"
filestring += "FOR010=\n"
filestring += "Band: 4 lines, "+deletenewline(self.docstring,replace=" ")+"\n"
filestring += "NITER.=200 NOB..= 2 NPRN.= 0 NFIX.= 0 MIXKEY= 2 NCOL.=Y PMODE=K\n"
filestring += "REP.....=B FIXD...=Y CRT....=S NB...= 16 CLSIZE= 32 NPROW= 0 NPCOL= 0\n"
filestring += "NKX...= 1 NKY..= 1 NKZ..= 1 TFERMI..= 2000.0(K)\n"
filestring += "AMIX.....= 0.100 TOLE....= 0.0000100 TOLEL...= 0.0000010\n"
# average wigner-seitz radius
nosites = 0
for a in self.cell.atomdata:
nosites += len(a)
volume = abs(det3(self.cell.latticevectors))
wsr = self.cell.lengthscale * (3*volume/(nosites * 4 * pi))**third
filestring += "SWS......= %9f NP...= 1 SMIX.= 0.500 TMIX.= 0.0000\n" % wsr
filestring += "Setup: 3 + NQ*NS*NP lines\n"
filestring += "EFGS.....= 0.0000 EFGS....= 0.00000 FTMAG...= 0.000000\n"
filestring += "DEO(l)...= 0.020 0.010 0.005 0.001 0.02\n"
filestring += "Symb IQ IT NL IP NSP SWP QTRO SPLT NFIX NDWF Eny(spdf)\n"
# set first species
if self.cell.atomdata[0][0].alloy():
prevspecies = "??"
else:
for v in self.cell.atomdata[0][0].species:
prevspecies = v
# type loop
iq = 1
it = 1
nsp = 1
for a in self.cell.atomdata:
for b in a:
if b.alloy():
species = "??"
else:
species = b.spcstring()
if species != prevspecies:
prevspecies = species
nsp += 1
tmpstring = species.ljust(2)+" "+str(iq).ljust(3)+str(it).ljust(3)
try:
tmpstring += str(l[ed.elementblock[species]]).ljust(3)+str(1).ljust(3)
except KeyError:
tmpstring += " ? 1"
tmpstring += str(nsp).ljust(3)
tmpstring += " 1.000 .000 0.00 0000 1111 .0 .0 .0 .0"
if b.alloy():
# print alloy components at the end of the line
tmpstring += " "+b.spcstring()
filestring += tmpstring+"\n"
iq += 1
it += 1
for a in self.cell.atomdata:
filestring += "Theta....= 90.00 Phia....= 0.00 FIXMOM..= N moment..= 0.0\n"
filestring += "PQX......= 0.00 PQY.....= 0.00 PQZ.....= 0.00000 COORD...=L\n"
filestring += "Atom: 4 lines + NT*6 lines\n"
filestring += "IEX...= 4 NP..=500 NES..= 15 NITER=250 IWAT.= 0\n"
filestring += "VMIX.....= 0.300000 RWAT....= 3.500000 RMAX....= 20.000000\n"
filestring += "DPAS.....= 0.049000 DR1.....= 1.00E-08 TEST....= 1.00E-08\n"
filestring += "TESTE....= 1.00E-07 TESTY...= 1.00E-08 TESTV...= 1.00E-07\n"
for a in self.cell.atomdata:
for comp in a[0].species:
filestring += comp+"\n"
try:
filestring += ed.emtoelements[comp]
except KeyError:
filestring += "\n\n\n\n\n"
return filestring
class BSTRFile(GeometryOutputFile):
"""
Class for storing the geometrical data needed in a [filename].dat file for the bstr program
and the method __str__ that outputs the contents of the .dat file as a string.
"""
def __init__(self,crystalstructure,string):
GeometryOutputFile.__init__(self,crystalstructure,string)
# Set atomic units for length scale
self.cell.newunit("bohr")
self.jobnam = "default"
self.a = 1
self.b = 1
self.c = 1
# To be put on the first line
self.programdoc = ""
def __str__(self):
ed = ElementData()
filestring = ""
tmpstring = "BSTR IDSYST= 7"
tmpstring = tmpstring.ljust(40)+deletenewline(self.programdoc,replace=" ")+"\n"
filestring += tmpstring
tmpstring = "JOBNAM...="+self.jobnam.ljust(9)+" MSGL.= 1 \n"
filestring += tmpstring
filestring += "MODE....=B STORE..=Y SCREEN.=B CMBC...=Y\n"
filestring += "FOR001=\n"
filestring += "FOR006=\n"
filestring += deletenewline(self.docstring,replace=" ")+"\n"
# Get number of sites
nosites = 0
for a in self.cell.atomdata:
nosites += len(a)
# Setting the real space summation cutoff to 4.5*(wigner-seitz radius)
volume = abs(det3(self.cell.latticevectors))
wsr = (3*volume/(nosites * 4 * pi))**third
tmpstring = "IALF...= 0 NPRN..= 1 DMAX....=%10.5f \n" % (wsr*4.5)
filestring += tmpstring
filestring += "ALF(spdf)= 0.3205350 0.0413320 0.0084290 0.0015370\nDKAPPA...= 0.00010\n"
tmpstring = "NQ3....=%3i LAT...= 0 IPRIM.= 0" % nosites
filestring += tmpstring
# Set up basis functions. Just setting lmax = 2 for s-/p-, 3 for d- and 4 for f- blocks
tmpstring = "\nNLX(IQ)..="
for a in self.cell.atomdata:
for b in a:
for k in b.species:
l = 1
if ed.elementblock[k] == "s" or ed.elementblock[k] == "p":
l = max(l,2)
elif ed.elementblock[k] == "d":
l = max(l,3)
elif ed.elementblock[k] == "f":
l = max(l,4)
tmpstring += " %1i" % l
if len(tmpstring) % 69 == 0:
tmpstring += "\n "
# Need to strip newline character if the last line was 69 characters long...
tmpstring = tmpstring.rstrip(string.whitespace)
tmpstring = tmpstring+"\n"
filestring += tmpstring
# Print lattice vectors
coa = self.c / self.a
boa = self.b / self.a
filestring += "A........= 1.00000000 B.......= 1.00000000 C.......= 1.00000000\n"
tmpstring = ""
lv = self.cell.latticevectors
for i in range(3):
tmpstring += "BSX......=%12.7f BSY.....=%12.7f BSZ.....=%12.7f\n" % (lv[i][0],lv[i][1],lv[i][2])
filestring += tmpstring
# All positions
it = 1
for a in self.cell.atomdata:
for b in a:
pos = mvmult3(lv,b.position)
tmpstring = "QX.......=%12.7f QY......=%12.7f QZ......=%12.7f" % (pos[0],pos[1],pos[2])
tmpstring += " "+b.spcstring()+"\n"
filestring += tmpstring
it += 1
filestring += "LAMDA....= 2.5000 AMAX....= 5.5000 BMAX....= 5.5000\n"
return filestring
################################################################################################
# RSPT FILES
class CellgenFile(GeometryOutputFile):
"""
Class for storing the geometrical data needed in a cellgen.inp file and the method
__str__ that outputs the contents of an cellgen.inp file as a string.
"""
def __init__(self,crystalstructure,string):
GeometryOutputFile.__init__(self,crystalstructure,string)
self.supercellmap = [[1,0,0],[0,1,0],[0,0,1]]
self.referencevector = [0,0,0]
# Set atomic units for length scale
self.cell.newunit("bohr")
# Make sure the docstring has comment form
self.docstring = self.docstring.rstrip("\n")
tmpstrings = self.docstring.split("\n")
self.docstring = ""
for string in tmpstrings:
string = string.lstrip("#")
string = "#"+string+"\n"
self.docstring += string
def __str__(self):
# Initialize element data
ed = ElementData()
# Add docstring
filestring = self.docstring
# Add lattice constant
filestring += "# Lattice constant in a.u.: "+str(self.cell.lengthscale)+"\n"
# RSPt reads the lattice vectors as columns...
filestring +="# Lattice vectors (columns)\n"
tmpstring = ""
for i in range(3):
for j in range(3):
tmpstring += "%19.15f "%self.cell.latticevectors[j][i]
tmpstring += "\n"
filestring += tmpstring
# Get number of sites
nosites = 0
for a in self.cell.atomdata:
nosites += len(a)
filestring += "# Sites\n"
filestring += str(nosites)+"\n"
it = 1
for a in self.cell.atomdata:
for b in a:
tmpstring = ""
tmpstring += str(b.position)+" "
if b.alloy():
# don't know what to put for an alloy
tmpstring += "???"
else:
tmpstring += "%3i"%ed.elementnr[b.spcstring()]
tmpstring += " l "+chr(it+96)+" # "+b.spcstring()+"\n"
filestring += tmpstring
it += 1
filestring += "# Supercell map\n"
tmpstring = ""
for i in self.supercellmap:
for j in i:
tmpstring += str(j).rjust(4)
tmpstring += "\n"
filestring += tmpstring
filestring += "# Reference vector\n"
tmpstring = ""
for i in self.referencevector:
tmpstring += "%19.15f "%i
tmpstring += "\n"
filestring += tmpstring
return filestring
################################################################################################
class SymtFile(GeometryOutputFile):
"""
Class for storing the geometrical data needed in an old format symt.inp file and the method
__str__ that outputs the contents of an symt.inp file as a string.
"""
def __init__(self,crystalstructure,string):
GeometryOutputFile.__init__(self,crystalstructure,string)
# Set atomic units for length scale
self.cell.newunit("bohr")
# Make sure the docstring has comment form
self.docstring = self.docstring.rstrip("\n")
tmpstrings = self.docstring.split("\n")
self.docstring = ""
for string in tmpstrings:
string = string.lstrip("#")
string = "#"+string+"\n"
self.docstring += string
# Default spin axis is [0,0,0]
self.spinaxis = [0.0, 0.0, 0.0]
self.rsptcartlatvects = False
self.passwyckoff = False
self.printlabels = False
def __str__(self):
# Initialize element data
ed = ElementData()
# Add docstring
filestring = self.docstring
# Add lattice constant
filestring += "# Lattice constant in a.u.: "+str(self.cell.lengthscale)+"\n"
# RSPt reads the lattice vectors as columns...
filestring +="# Lattice vectors (columns)\n"
if self.rsptcartlatvects:
fac = self.cell.lengthscale
else:
fac = 1.0
tmpstring = ""
for i in range(3):
for j in range(3):
tmpstring += "%19.15f "%(self.cell.latticevectors[j][i]*fac)
tmpstring += "\n"
filestring += tmpstring
filestring += "# Spin axis\n"
filestring += "%19.15f %19.15f %19.15f l\n"%(self.spinaxis[0],self.spinaxis[1],self.spinaxis[2])
# Get number of sites
nosites = 0
for a in self.cell.atomdata:
nosites += len(a)
filestring += "# Sites\n"
filestring += str(nosites)+"\n"
it = 1
label = "a"
for a in self.cell.atomdata:
for b in a:
tmpstring = ""
tmpstring += str(b.position)+" "
if b.alloy():
# don't know what to put for an alloy
tmpstring += "???"
else:
tmpstring += "%3i"%ed.elementnr[b.spcstring()]
if self.passwyckoff:
label = chr(it+96)
if self.printlabels:
tmpstring += " l "+label+" # "+b.label+"\n"
else:
tmpstring += " l "+label+" # "+b.spcstring()+"\n"
filestring += tmpstring
it += 1
return filestring
################################################################################################
class SymtFile2(GeometryOutputFile):
"""
Class for storing the geometrical data needed in a new format symt.inp file and the method
__str__ that outputs the contents of an symt.inp file as a string.
"""
def __init__(self,crystalstructure,string,kresolution=0.1):
GeometryOutputFile.__init__(self,crystalstructure,string)
# Set atomic units for length scale
self.cell.newunit("bohr")
# Make sure the docstring has comment form
self.docstring = self.docstring.rstrip("\n")
tmpstrings = self.docstring.split("\n")
self.docstring = ""
for string in tmpstrings:
string = string.lstrip("#")
string = "#"+string+"\n"
self.docstring += string
# Default spin axis is [0,0,0]
self.spinaxis = Vector([0.0, 0.0, 0.0])
# parameters for spin polarization
self.spinpol = False
self.relativistic = False
self.forcenospin = False
self.rsptcartlatvects = False
self.mtradii = 0
self.passwyckoff = False
# k-mesh generation etc.
self.setupall = False
self.kresolution = kresolution
self.nokshifts = False
self.kshifts = [[0,0,0],[1,1,1]]
self.printlabels = False
def __str__(self):
# Initialize element data
ed = ElementData()
# Add docstring
filestring = self.docstring
# Add lattice constant
filestring += "# Lattice constant in a.u.\n"
filestring += "lengthscale\n"
if self.rsptcartlatvects:
filestring += "1.000 \n"
else:
filestring += str(self.cell.lengthscale)+"\n"
if self.spinpol and not self.forcenospin:
filestring += "# Spin polarized calculation\nspinpol\n"
filestring += "# Spin polarize atomic densities\nspinpol_atomdens\n"
if self.relativistic:
if self.setupall:
filestring += "# Relativistic symmetries\nspinorbit\n"
else:
filestring += "# Relativistic symmetries\nfullrel\n"
# Default to z-direction for relativistic calculations...
t = self.spinaxis - Vector([0.,0.,0.])
if t.length() < 1e-7:
self.spinaxis = mvmult3(minv3(self.cell.latticevectors),Vector([0.,0.,1.]))
# ... unless these space group settings, when we pick a more likely high-symmetry axis
if self.cell.spacegroupsetting == "A":
self.spinaxis = mvmult3(minv3(self.cell.latticevectors),Vector([1.,0.,0.]))
elif self.cell.spacegroupsetting == "B":
self.spinaxis = mvmult3(minv3(self.cell.latticevectors),Vector([0.,1.,0.]))
if self.mtradii != 0:
filestring += "# Choice of MT radii\n"
filestring += "mtradii\n"+str(self.mtradii)+"\n"
# RSPt reads the lattice vectors as columns...
filestring += "# Lattice vectors (columns)\n"
filestring += "latticevectors\n"
tmpstring = ""
if self.rsptcartlatvects:
fac = self.cell.lengthscale
else:
fac = 1.0
for i in range(3):
for j in range(3):
tmpstring += "%19.15f "%(self.cell.latticevectors[j][i]*fac)
tmpstring += "\n"
filestring += tmpstring
filestring += "# Spin axis\n"
filestring += "spinaxis\n"
filestring += "%19.15f %19.15f %19.15f l\n"%(self.spinaxis[0],self.spinaxis[1],self.spinaxis[2])
# Get number of sites
nosites = 0
for a in self.cell.atomdata:
nosites += len(a)
filestring += "# Sites\n"
filestring += "atoms\n"
filestring += str(nosites)+"\n"
it = 1
label = "a"
for a in self.cell.atomdata:
for b in a:
label = "a"
tmpstring = ""
tmpstring += str(b.position)+" "
if b.alloy():
# don't know what to put for an alloy
tmpstring += "???"
else:
tmpstring += "%3i"%ed.elementnr[b.spcstring()]
if self.passwyckoff:
label = chr(it+96)
if self.setupall and b.spcstring() in suspiciouslist and not self.forcenospin:
label = "up"
if self.printlabels:
tmpstring += " l "+label+" # "+b.label+"\n"
else:
tmpstring += " l "+label+" # "+b.spcstring()+"\n"
filestring += tmpstring
it += 1
# k-mesh setup for new input
if self.setupall:
# Using k-resolution together with Froyen map needs supervised choice of mesh,
# or they easily become unnecessarily dense, so don't use this feature.
## filestring += "\n"
## filestring += "# k space resolution\n"
## filestring += "kresolution\n"
## filestring += " %f\n"%(self.kresolution)
# Guess a suitable Froyen map !!! Column vectors for RSPt !!!
mapmatrix = LatticeMatrix([[1,0,0],[0,1,0],[0,0,1]])
if self.cell.primcell:
if self.cell.spacegroupsetting == 'F':
mapmatrix = LatticeMatrix([[1,1,0],[1,0,1],[0,1,1]])
elif self.cell.spacegroupsetting == 'I':
if self.cell.crystal_system() == 'cubic':
mapmatrix = LatticeMatrix([[-1,1,1],[1,-1,1],[1,1,-1]])
else:
mapmatrix = LatticeMatrix([[2,0,1],[0,2,1],[0,0,2]])
elif self.cell.spacegroupsetting == 'A':
mapmatrix = LatticeMatrix([[1,0,0],[0,1,-1],[0,1,1]])
elif self.cell.spacegroupsetting == 'B':
mapmatrix = LatticeMatrix([[1,0,-1],[0,1,0],[1,0,1]])
elif self.cell.spacegroupsetting == 'C':
mapmatrix = LatticeMatrix([[1,-1,0],[1,1,0],[0,0,1]])
elif self.cell.spacegroupsetting == 'R' and abs(self.cell.latticevectors[0].angle(self.cell.latticevectors[1])*180/pi) > 10:
# Generate in hexagonal supercell unless the rhombohedral angle is close to 90 degrees.
mapmatrix = LatticeMatrix([[1,0,1],[-1,1,1],[0,-1,1]])
# Determine mesh
reclatvect = LatticeMatrix(mmmult3(self.cell.reciprocal_latticevectors().transpose(),mapmatrix)).transpose()
for j in range(3):
for i in range(3):
reclatvect[j][i] = reclatvect[j][i] / self.cell.lengthscale
# Lengths of reciprocal lattice vectors
reclatvectlen = [elem.length() for elem in reclatvect]
kgrid = [max(1,int(round(elem/self.kresolution))) for elem in reclatvectlen]
# Manual adjustments to make the choice work well with the Froyen mesh.
# Some centerings should have even meshes, for rhombohedral it should be dividable by 3
# along c.
if self.cell.primcell:
if self.cell.spacegroupsetting == 'F' or self.cell.spacegroupsetting == "I":
for i in range(3):
kgrid[i] += kgrid[i]%2
elif self.cell.spacegroupsetting == 'A':
kgrid[1] += kgrid[1]%2
kgrid[2] += kgrid[2]%2
elif self.cell.spacegroupsetting == 'B':
kgrid[0] += kgrid[0]%2
kgrid[2] += kgrid[2]%2
elif self.cell.spacegroupsetting == 'C':
kgrid[0] += kgrid[0]%2
kgrid[1] += kgrid[1]%2
elif self.cell.spacegroupsetting == 'R' and abs(self.cell.latticevectors[0].angle(self.cell.latticevectors[1])*180/pi) > 10:
for i in range(3):
# This rounds to nearest multiple of 3
if kgrid[i]%3 == 1:
kgrid[i] -= 1
elif kgrid[i]%3 == 2:
kgrid[i] += 1
filestring += "\n# k-points\n"
filestring += "kpoints\n"
filestring += " %i %i %i\n\n"%(kgrid[0], kgrid[1], kgrid[2])
# Write Froyen map.
filestring += "# Froyen map\n"
filestring += "kmapmatrix\n"
for v in mapmatrix:
filestring += " %4i %4i %4i\n"%(v[0],v[1],v[2])
# Return
return filestring
################################################################################################
class Crystal09File(GeometryOutputFile):
"""
Class for storing the geometrical data needed by Crystal09 and the method
__str__ that outputs the contents of an Crystal09 input file as a string.
Presently only handles standard settings (space group numbers, not H-M symbols)
"""
def __init__(self,crystalstructure,string):
GeometryOutputFile.__init__(self,crystalstructure,string)
self.HermannMauguin = ""
self.spacegroupnr = 0
self.a = 1
self.b = 1
self.c = 1
self.alpha = 90
self.beta = 90
self.gamma = 90
self.trigonalsetting = "H"
# Set atomic units for length scale
self.cell.newunit("angstrom")
# Make sure the docstring has the form of a f90 comment
self.docstring = self.docstring.rstrip("\n")
tmpstrings = self.docstring.split("\n")
self.docstring = ""
for string in tmpstrings:
string = string.lstrip("!")
string = "!"+string+"\n"
self.docstring += string
def __str__(self):
# Initialize element data
ed = ElementData()
# Add docstring
filestring = self.docstring
filestring += "CRYSTAL\n"
system = crystal_system(self.spacegroupnr)
# Space group setting and crystal parameters
if system == "triclinic":
filestring += "0 0 0\n"
filestring += str(self.spacegroupnr)+"\n"
filestring += "%13.8f %13.8f %13.8f %13.8f %13.8f %13.8f\n"%(self.a, self.b, self.c, self.alpha, self.beta, self.gamma)
elif system == "monoclinic":
filestring += "0 0 0\n"
filestring += str(self.spacegroupnr)+"\n"
filestring += "%13.8f %13.8f %13.8f %13.8f\n"%(self.a, self.b, self.c, self.beta)
elif system == "orthorhombic":
filestring += "0 0 0\n"
filestring += str(self.spacegroupnr)+"\n"
filestring += "%13.8f %13.8f %13.8f\n"%(self.a, self.b, self.c)
elif system == "tetragonal":
filestring += "0 0 0\n"
filestring += str(self.spacegroupnr)+"\n"
filestring += "%13.8f %13.8f\n"%(self.a, self.c)
elif system == "trigonal":
if self.trigonalsetting == "H":
filestring += "0 0 0\n"
filestring += str(self.spacegroupnr)+"\n"
filestring += "%13.8f %13.8f\n"%(self.a, self.c)
elif self.trigonalsetting == "R":
filestring += "0 1 0\n"
filestring += str(self.spacegroupnr)+"\n"
filestring += "%13.8f %13.8f\n"%(self.a, self.alpha)
else:
return "***Error: No such trigonal setting : "+self.trigonalsetting
elif system == "hexagonal":
filestring += "0 0 0\n"
filestring += str(self.spacegroupnr)+"\n"
filestring += "%13.8f %13.8f\n"%(self.a, self.c)
elif system == "cubic":
filestring += "0 0 0\n"
filestring += str(self.spacegroupnr)+"\n"
filestring += "%13.8f\n"%(self.a)
else:
if self.force:
sys.stderr.write("***Warning: Could not determine crystal system corresponding to space group "+str(self.spacegroupnr)+".")
filestring += "0 0 0\n"
filestring += str(self.spacegroupnr)+"\n"