/
classes.py
executable file
·5073 lines (3502 loc) · 173 KB
/
classes.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
# -*- coding: utf-8 -*-
#Copyright Aksyonov D.A
from __future__ import division, unicode_literals, absolute_import, print_function
import itertools, os, copy, math, glob, re, shutil, sys, pickle
import re
from small_functions import angle, is_string_like
#additional packages
try:
from tabulate import tabulate
except:
print('tabulate is not avail')
try:
import pandas as pd
except:
print('pandas is not avail')
# import pymatgen
# sys.exit()
try:
import pymatgen
from pymatgen.io.cif import CifWriter
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from pymatgen.core.surface import Slab
from pymatgen.core.composition import Composition
pymatgen_flag = True
except:
print('pymatgen is not avail')
pymatgen_flag = False
import numpy as np
# import matplotlib.pyplot as plt
#siman packages
import header
from header import printlog, print_and_log, runBash, plt
from small_functions import cat_files, grep_file, red_prec, list2string, is_list_like
from functions import (read_vectors, read_list, words,
element_name_inv, invert, calculate_voronoi,
get_from_server, push_to_server, run_on_server, smoother, file_exists_on_server)
from inout import write_xyz, write_lammps, read_xyz
from small_functions import makedir
from geo import calc_recip_vectors, calc_kspacings, xred2xcart, xcart2xred, local_surrounding, determine_symmetry_positions
from geo import image_distance, replic
"""
Classes used in siman
TODO:
1. Please combine calculate_nbands(), calc_kspacings(), magmom filling in make incar with actualize_set()
2. split make_incar_and_copy_all() into make_incar() and copy_calc_files_to_cluster()
3. split .read_results() into download_output_files() and .parse_outcar() and .analyze_output()
4. outcar name should be returned by write_sge_script in all cases and used, now only in u_ramping
5. write_sge() - в режиме inherit_option = continue - предыдущие outcar резервируются только один
раз с префиксом prev, повторный запуск перезатрет их, поэтому нужно писать спец код
типа
if test -f prev1.outcar
cp name prev2+name
чтобы она находила prev3 с максимальным числом, и к этому числу прибавляла единицу для нового файла
NEW:
Calculation Structure():
*self.magmom* (list) - magnetic moments for each ion in structure; has higher preference than self.set.magnetic_moments which
include only moments for atom types
"""
class cd:
"""Context manager for changing the current working directory"""
def __init__(self, newPath):
self.newPath = os.path.expanduser(newPath)
def __enter__(self):
self.savedPath = os.getcwd()
os.chdir(self.newPath)
def __exit__(self, etype, value, traceback):
os.chdir(self.savedPath)
class Description():
"""
Objects of this class include just folder and description of specific calculation.
Mostly was needed for manual addition of new calculations
self.ngkpt_dict_for_kspacings (dict of lists) - the key is kspacing; the dict
contains k-meshes
for all calculations
based on this geometry structure.
can be useful for fine tuning of k-mesh for specific kspacing.
"""
def __init__(self, sectionfolder = "forgot_folder", description = "forgot_description"):
self.des = description
self.sfolder = sectionfolder
self.ngkpt_dict_for_kspacings = {} #the key is kspacing
class empty_struct():
def __init__(self):
pass
class Structure():
"""This class includes only structure related information such as primitive vectors, coordinates, forces and so on"""
def __init__(self):
self.name = ""
self.des = ''
self.hex_a = None
self.hex_c = None
self.gbpos = None
self.rprimd = [np.zeros((3)) for i in [0,1,2] ]
self.xcart = []
self.xred = []
self.magmom = []
self.select = [] # flags for selective dynamics
def new(self):
return Structure()
def selective_all(self):
st = copy.deepcopy(self)
# if hasattr(self, 'select'):
st.select = []
for i in range(st.natom):
st.select.append([True,True,True])
return st
def check_selective(self):
"""
check if some atoms should be frozen
"""
selective_dyn = False
if self.select is not None:
for sel in self.select:
# print (not all(sel))
if not all(sel):
selective_dyn = True
return selective_dyn
def fix_layers(self, xred_range, highlight = False):
"""
fix atoms in layers normal to R3
xred_range (list) [from, to]
highlight - replace with Pu to check
"""
st = copy.deepcopy(self)
if not hasattr(st, 'select'):
st = st.selective_all()
fixed = []
for i, xr in enumerate(st.xred):
if xred_range[0] < xr[2] < xred_range[1]:
st.select[i] = [0, 0, 0] # fix
fixed.append(i)
if highlight:
st = st.replace_atoms(fixed, 'Pu')
st.name+='_fix'
return st
def get_layers_pos(self, xred_range):
#return layer positions along vector 3 in xred_range
st = self
zred_req = []
for i, xr in enumerate(st.xred):
z =xr[2]
if xred_range[0] < z < xred_range[1]:
if len(zred_req) == 0:
zred_req.append(z)
m = min(np.abs(np.array(zred_req) - z))
# print()
if m > 0.05/np.linalg.norm(st.rprimd[2]): #tolerance 0.1 A
zred_req.append(xr[2])
z_unique = sorted(zred_req)
return z_unique
def xcart2xred(self,):
self.xred = xcart2xred(self.xcart, self.rprimd)
self.natom = len(self.xred)
def update_xred(self,):
self.xred = xcart2xred(self.xcart, self.rprimd)
self.natom = len(self.xred)
def xred2xcart(self,):
self.xcart = xred2xcart(self.xred, self.rprimd)
def update_xcart(self,):
self.xcart = xred2xcart(self.xred, self.rprimd)
def get_volume(self):
self.vol = np.dot( self.rprimd[0], np.cross(self.rprimd[1], self.rprimd[2]) ); #volume
return self.vol
def get_recip(self):
"""Calculate reciprocal vectors"""
self.recip = calc_recip_vectors(self.rprimd)
return self.recip
def get_nznucl(self):
"""list of numbers of atoms of each type, order is not important
updated directly
"""
self.nznucl = []
for typ in range(1,self.ntypat+1):
self.nznucl.append( self.typat.count(typ) )
return self.nznucl
def get_elements(self):
#return list of elements names
return [element_name_inv(self.znucl[t-1]) for t in self.typat]
def get_elements_z(self):
#return list of elements names
return [self.znucl[t-1] for t in self.typat]
def get_elements_zval(self):
#return list with number of valence electrons for each element
zvals = []
for z in self.get_elements_z():
i = self.znucl.index(z)
zv = self.zval[i]
zvals.append(zv)
return zvals
def get_maglist(self):
#return bool list of which elements are magnetic (here all transition metals are searched!)
#and dictionary with numbers of each transition metal
ifmaglist = []
zlist = self.get_elements_z()
mag_numbers = {}
for i, z in enumerate(zlist): #
if z in header.TRANSITION_ELEMENTS:
if z not in mag_numbers:
mag_numbers[z] = []
ifmaglist.append(True)
mag_numbers[z].append(i)
else:
ifmaglist.append(False)
ifmaglist = np.array(ifmaglist)
return ifmaglist, mag_numbers
def convert2pymatgen(self, oxidation = None, slab = False):
"""
oxidation (dict) - {'Ti':'Ti3+'}
slab - if True return slab object is returned - limited functional is implemented
"""
site_properties = {}
if hasattr(self, 'magmom') and any(self.magmom):
site_properties["magmom"] = self.magmom
if oxidation is None:
elements = self.get_elements()
else:
elements = [oxidation[el] for el in self.get_elements()]
if slab:
# print(dir(pymatgen.core))
pm = Slab(self.rprimd, elements, self.xred,
miller_index = [0,0,1], oriented_unit_cell = None, shift = None, scale_factor = None,reorient_lattice = False,
site_properties = site_properties)
else:
pm = pymatgen.Structure(self.rprimd, elements, self.xred, site_properties = site_properties)
if hasattr(self, 'charges') and any(self.charges):
if 1: #normalize charges
t = sum(self.charges)/len(self.charges)
chg = [c-t for c in self.charges ]
# print(t)
else:
chg = self.charges
pm.add_oxidation_state_by_site(chg)
return pm
def get_pm_composition(self):
''
pm = self.convert2pymatgen()
cm = Composition(pm.formula)
return cm
def get_reduced_formula(self):
''
pm = self.convert2pymatgen()
cm = Composition(pm.formula)
# cm = Composition(self.get_elements())
return cm.reduced_formula
def get_formula(self):
''
# pm = self.convert2pymatgen()
# cm = Composition(pm.formula)
# cm = Composition(self.get_elements())
return self.convert2pymatgen().formula
def get_reduced_composition(self):
''
pm = self.convert2pymatgen()
cm = Composition(pm.formula)
# cm = Composition(self.get_elements())
return cm.reduced_composition
def get_reduced_formula_and_factor(self):
pm = self.convert2pymatgen()
cm = Composition(pm.formula)
# cm = Composition(self.get_elements())
return cm.get_reduced_formula_and_factor()
def get_fractional_composition(self):
pm = self.convert2pymatgen()
cm = Composition(pm.formula)
# cm = Composition(self.get_elements())
return cm.fractional_composition
def update_types(self, elements):
# update typat, ntypat, znucl, nznucl from elements - list of elements names
st = copy.deepcopy(self)
st.ntypat = len(set(elements))
st.typat = []
st.znucl = []
unique = []
curtyp = 0
types = {}
for el in elements:
if el not in unique:
curtyp += 1
types[el] = curtyp
if is_string_like(el):
z = invert(el)
else:
z = el
st.znucl.append(z)
# nznucl.append(0)
unique.append(el)
st.typat.append(types[el])
st.get_nznucl()
# print(st.ntypat, st.typat, st.nznucl, st.znucl)
return st
def update_from_pymatgen(self, stpm):
"""
stpm - pymatgen structure
update the current structure from pymatgen structure
only rprimd, xred and xcart are updated now!!!!!
TODO:
please update magmom also!!!!
"""
st = copy.deepcopy(self)
st.rprimd = [np.array(vec) for vec in stpm._lattice._matrix]
st.xred = [np.array(site._fcoords) for site in stpm._sites]
# print(elements)
st.update_xcart()
s = stpm._sites[0]
# print( dir(s.specie) )
# print( s.specie )
elements = [s.specie.name for s in stpm._sites]
# print(s.specie.oxi_state)
if hasattr(s.specie, 'oxi_state'):
charges = [s.specie.oxi_state for s in stpm._sites]
st.charges = charges
# print(st.charges)
# else:
# charges = [None]
# print(elements)
# print(charges)
# sys.exit()
st = st.update_types(elements)
st.natom = len(st.typat)
# sys.exit()
if st.natom != len(st.xred):
printlog('Error! number of atoms was changed, please improve this method')
st.name+='_from_pmg'
return st
def printme(self):
print(self.convert2pymatgen())
return
def get_space_group_info(self, symprec = None):
default = 0.01
if not symprec:
symprec = default
if hasattr(self, 'spg') and symprec == default:
spg = self.spg
else:
p = self.convert2pymatgen()
spg = p.get_space_group_info(symprec)
# p = self.convert2pymatgen()
# print(p.get_symmetry_operations(symprec))
return spg
def sg(self,symprec = None, silent = 0):
try:
s = self.get_space_group_info(symprec)
except:
s = 'error'
if not silent:
print(s)
return s
def get_angles(self):
R = self.rprimd
alpha = angle(R[1], R[2])
beta = angle(R[0], R[2])
gamma = angle(R[0], R[1])
return alpha, beta, gamma
# def __str__(self):
# # print(self.convert2pymatgen())
# return
def get_element_xred(self, element):
"""
Get xred of *element* first occurance
"""
i = self.get_elements().index(element)
return self.xred[i]
def get_element_xcart(self, element):
"""
Get xred of *element* first occurance
"""
i = self.get_elements().index(element)
return self.xcart[i]
def get_transition_elements(self, fmt = 'names'):
"""Returns list of transition elements (chemical names or z) in the structure
fmt -
'names'
'z'
'n' - numbers of atoms
"""
el = self.get_elements()
tra = []
ns = []
for i, e in enumerate(el):
for t in header.TRANSITION_ELEMENTS:
if e == invert(t):
tra.append(e)
ns.append(i)
if fmt == 'z':
tra = [invert(t) for t in tra]
elif fmt == 'n':
tra = ns
return tra
def get_specific_elements(self, required_elements = None, fmt = 'names', ):
"""Returns list of transition elements (chemical names or z) in the structure
fmt -
'names'
'z'
'n' - numbers of atoms
required_elements - list of elements of interest
"""
el = self.get_elements()
tra = []
ns = []
for i, e in enumerate(el):
for t in required_elements:
if e == invert(t):
tra.append(e)
ns.append(i)
if fmt == 'z':
tra = [invert(t) for t in tra]
elif fmt == 'n':
tra = ns
return tra
def add_atoms(self, atoms_xcart, element = 'Pu', return_ins = False, selective = None):
"""
appends at the end if element is new. Other case insertered according to VASP conventions
Updates ntypat, typat, znucl, nznucl, xred, magmom and natom
atoms_xcart (list of ndarray)
selective (list of lists) - selective dynamics
magmom is appended with 0.6, please improve me! by using other values for magnetic elements
if return_ins:
Returns Structure(), int - place of insertion of first atom
else:
Structure()
"""
printlog('self.add_atoms(): adding atom ', element, imp = 'n')
st = copy.deepcopy(self)
if not hasattr(st, 'select') or st.select is None:
st = st.selective_all()
natom_to_add = len(atoms_xcart)
st.natom+=natom_to_add
el_z_to_add = element_name_inv(element)
if hasattr(st, 'magmom') and any(st.magmom):
magmom_flag = True
else:
magmom_flag = False
if el_z_to_add not in st.znucl:
st.znucl.append( el_z_to_add )
st.nznucl.append(natom_to_add)
st.ntypat+=1
typ = max(st.typat)+1
st.xcart.extend(atoms_xcart)
st.typat.extend( [typ]*natom_to_add )
if selective is not None:
st.select.extend(selective)
else:
st.select.extend( [[1,1,1] for i in range(natom_to_add)] )
if magmom_flag:
st.magmom.extend( [0.6]*natom_to_add )
j_ins = self.natom # first one
else:
i = st.znucl.index(el_z_to_add)
st.nznucl[i]+=natom_to_add
typ = i+1
for j, t in enumerate(st.typat):
if t == typ:
j_ins = j+1 # place to insert
st.xcart[j_ins:j_ins] = atoms_xcart
st.typat[j_ins:j_ins] = [typ]*natom_to_add
if selective is not None:
st.select[j_ins:j_ins] = selective
else:
st.select[j_ins:j_ins] = [[1,1,1] for i in range(natom_to_add)]
if magmom_flag:
st.magmom[j_ins:j_ins] = [0.6]*natom_to_add
st.xcart2xred()
if return_ins:
return st, j_ins
else:
return st
def add_atom(self, xr = None, element = 'Pu', xc = None, selective = None):
"""
wrapper
allows to add one atom using reduced coordinates or cartesian
"""
if xr is not None:
''
xc = xred2xcart([xr], self.rprimd)[0]
elif xc is not None:
''
else:
''
printlog('Error! Provide reduced *xr* or cartesian *xc* coordinates!')
if selective is not None:
selective = [selective]
st = self.add_atoms([xc], element = element, selective = selective)
return st
def reorder_for_vasp(self, inplace = False):
"""
Group and order atoms by atom types; consistent with VASP
return st
"""
''
if inplace:
st = self
else:
st = copy.deepcopy(self)
nt = range(st.ntypat)
zxred = [[] for i in nt]
zxcart = [[] for i in nt]
ztypat = [[] for i in nt]
zmagmom= [[] for i in nt]
ziat = [[] for i in nt]
i = 0
# print(st.ntypat)
for t, xr, xc in zip(st.typat, st.xred, st.xcart):
# print ("t ", t, xr)
zxred[ t-1].append(xr)
zxcart[t-1].append(xc)
ztypat[t-1].append(t)
ziat[t-1].append(i)
i+=1
st.nznucl = [len(typat) for typat in ztypat]
st.xcart = [item for sublist in zxcart for item in sublist]
st.xred = [item for sublist in zxred for item in sublist]
st.typat = [item for sublist in ztypat for item in sublist]
original_numbers = [item for sublist in ziat for item in sublist]
st.perm = [original_numbers.index(i) for i in range(st.natom)] # show the initial order of atoms; starting from 0
if hasattr(st, 'magmom') and any(st.magmom):
for t, m in zip(st.typat, st.magmom):
zmagmom[t-1].append(m)
st.magmom = [item for sublist in zmagmom for item in sublist]
else:
st.magmom = [None]
# print(st.get_elements())
# print(st.perm)
return st
def del_atom(self, iat):
"""
Now can delete only one atom with number iat (int), starting from 0.
Takes care of magmom, ntypat, typat, znucl, nznucl, xred and natom
Returns Structure()
"""
# print_and_log('Warning! Method del_atoms() was not carefully tested ')
st = copy.deepcopy(self)
# print(st.nznucl)
i = iat
typ = st.typat[i]
printlog('del_atom(): I remove atom ', st.get_elements()[i], imp = 'n')
del st.typat[i]
del st.xred[i]
del st.xcart[i]
# print ('Magmom deleted?')
# print(st.magmom)
if hasattr(st, 'magmom') and any(st.magmom):
del st.magmom[i]
# print ('Yes!')
else:
''
# print ('No!')
st.natom-=1
if typ in st.typat:
st.nznucl[typ-1]-=1
else:
del st.nznucl[typ-1]
del st.znucl[typ-1]
st.ntypat-=1
# for i, n in enumerate(st.nznucl):
# typ = i+1
# st.typat = [typ, ]
for i, t in enumerate(st.typat):
if t > typ:
st.typat[i]-=1
# print(st.nznucl)
return st
def mov_atoms(self, iat = None, to_x = None):
"""
Move one atom to xcart position *to_x*
"""
st = copy.deepcopy(self)
st.xcart[iat] = to_x
st.xcart2xred()
return st
def swap_atoms(self, iat1, iat2):
st = copy.deepcopy(self)
x1 = st.xcart[iat1]
st.xcart[iat1] = st.xcart[iat2]
st.xcart[iat2] = x1
st.xcart2xred()
return st
def leave_only(self, atom_type = None):
#Remove all atoms except *atom_type*(str, mendeleev element name)
print_and_log('Starting leave_only()', imp = 'n')
st = copy.deepcopy(self)
print_and_log(' N of atoms before = ',st.natom, imp = 'n')
z = element_name_inv(atom_type)
new_xred = []
new_magmom = []
if hasattr(st, 'magmom') and any(st.magmom):
for t, xr, m in zip(st.typat, st.xred, st.magmom):
if st.znucl[t-1] == z:
new_xred.append(xr)
new_magmom.append(m)
else:
for t, xr in zip(st.typat, st.xred):
if st.znucl[t-1] == z:
new_xred.append(xr)
st.magmom = new_magmom
st.xred = new_xred
st.natom = len(new_xred)
st.ntypat = 1
st.typat = [1]*st.natom
st.znucl = [z,]
st.nznucl = [st.natom,]
st.xcart = xred2xcart(st.xred, st.rprimd)
# print st.xred
print_and_log(' N of atoms after = ',st.natom, imp = 'n')
return st
def get_numbers(self, element):
"return numbers of specific element "
return [i for i, el in enumerate(self.get_elements()) if el == element]
def remove_atoms(self, atoms_to_remove, from_one = 0):
"""
remove atoms either of types provided in *atoms_to_remove* or having numbers provided in *atoms_to_remove*, starting from 0
st (Structure)
atoms_to_remove (list) - list of element names or numbers
from_one (int)- if 1 the numbers of atoms in provided list are starting from one
"""
st = copy.deepcopy(self)
# print(st.nznucl)
numbers = list(range(st.natom))
atom_exsist = True
while atom_exsist:
for i, (n, el) in enumerate( zip(numbers, st.get_elements()) ):
# print(i)
if el in atoms_to_remove or n+from_one in atoms_to_remove:
# print(n)
# atoms_to_remove.remove(i)
st = st.del_atom(i)
del numbers[i]
break
else:
atom_exsist = False
printlog('remove_atoms(): Atoms', atoms_to_remove, 'were removed')
st.magmom = [None]
# print(st.nznucl)
# print(st.get_elements())
return st
def del_layers(self, xred_range,):
"""
fix atoms in layers normal to R3
xred_range (list) [from, to]
highlight - replace with Pu to check
"""
st = copy.deepcopy(self)
# print(st.nznucl)
dels = []
for i, xr in enumerate(st.xred):
if xred_range[0] < xr[2] < xred_range[1]:
# print(xred_range[0], xr[2], xred_range[1])
dels.append(i)
# print(dels)
st = st.remove_atoms(dels)
st.name+='_del'
# print(st.nznucl)
return st
def replace_atoms(self, atoms_to_replace, el_new):
"""
atoms_to_replace - list of atom numbers starting from 0
el_new - new element
"""
st = copy.deepcopy(self)
numbers = list(range(st.natom))
atom_exsist = True
while atom_exsist:
for i, (n, el) in enumerate( zip(numbers, st.get_elements()) ):
# print(i)
if n in atoms_to_replace:
xcart = st.xcart[i]
print('replace_atoms(): atom', i, st.get_elements()[i], 'replaced with', el_new)
st = st.del_atom(i)
st = st.add_atoms([xcart], element = el_new)
# print(st.natom)
# print(st.get_elements())
# print(st.natom)
# print(st.get_elements())
del numbers[i]
break
else:
atom_exsist = False
# printlog('remove_atoms(): Atoms', atoms_to_remove, 'were removed')
# print(st.get_elements())
return st
def remove_part(self, element, new_conc):
"""
element to remove
new_conc <1 - new concentration of element atoms (part of unity)
"""
st = copy.deepcopy(self)
numb = self.get_numbers(element)
nat_el = int(np.ceil((len(numb)*new_conc)))
printlog('New number of ', element, 'atoms is ', nat_el, imp = 'y')
del_num = numb[nat_el:len(numb)]
return st.remove_atoms(del_num)
def add_vacuum(self, vec, thick):
"""
To be improved
vector - along which vector, 0, 1, 2
thick - thickness of vector
TODO: