提取xsd文件坐标并操作


In [1]:
from vaspy.matstudio import XsdFile

In [2]:
xsd = XsdFile('h_top_c_fcc_far.xsd')

显示坐标


In [4]:
xsd.data


Out[4]:
array([[ 0.2972892 ,  0.15463501,  0.43569139],
       [ 0.73186612,  0.37097034,  0.41434976],
       [ 0.48259474,  0.25402011,  0.47432829],
       [ 0.07330592,  0.05287656,  0.01079317],
       [ 0.07330592,  0.55287657,  0.01079317],
       [ 0.57330592,  0.05287656,  0.01079317],
       [ 0.57330592,  0.55287656,  0.01079317],
       [ 0.73997259,  0.3862099 ,  0.12308022],
       [ 0.73997259,  0.8862099 ,  0.12308022],
       [ 0.23997259,  0.3862099 ,  0.12308022],
       [ 0.23997259,  0.8862099 ,  0.12308022],
       [ 0.40899389,  0.21427639,  0.23349414],
       [ 0.91185849,  0.71681419,  0.2345969 ],
       [ 0.91211185,  0.21548399,  0.23483813],
       [ 0.40209504,  0.71118551,  0.23451221],
       [ 0.09123061,  0.04977886,  0.35005352],
       [ 0.58588392,  0.55240731,  0.34386542],
       [ 0.08125505,  0.54466019,  0.35622431],
       [ 0.58650079,  0.04224914,  0.344275  ]])

In [5]:
xsd.data + 0.01


Out[5]:
array([[ 0.3072892 ,  0.16463501,  0.44569139],
       [ 0.74186612,  0.38097034,  0.42434976],
       [ 0.49259474,  0.26402011,  0.48432829],
       [ 0.08330592,  0.06287656,  0.02079317],
       [ 0.08330592,  0.56287657,  0.02079317],
       [ 0.58330592,  0.06287656,  0.02079317],
       [ 0.58330592,  0.56287656,  0.02079317],
       [ 0.74997259,  0.3962099 ,  0.13308022],
       [ 0.74997259,  0.8962099 ,  0.13308022],
       [ 0.24997259,  0.3962099 ,  0.13308022],
       [ 0.24997259,  0.8962099 ,  0.13308022],
       [ 0.41899389,  0.22427639,  0.24349414],
       [ 0.92185849,  0.72681419,  0.2445969 ],
       [ 0.92211185,  0.22548399,  0.24483813],
       [ 0.41209504,  0.72118551,  0.24451221],
       [ 0.10123061,  0.05977886,  0.36005352],
       [ 0.59588392,  0.56240731,  0.35386542],
       [ 0.09125505,  0.55466019,  0.36622431],
       [ 0.59650079,  0.05224914,  0.354275  ]])

每个坐标数值增加0.01


In [6]:
xsd.data += 0.01

In [7]:
xsd.data


Out[7]:
array([[ 0.3072892 ,  0.16463501,  0.44569139],
       [ 0.74186612,  0.38097034,  0.42434976],
       [ 0.49259474,  0.26402011,  0.48432829],
       [ 0.08330592,  0.06287656,  0.02079317],
       [ 0.08330592,  0.56287657,  0.02079317],
       [ 0.58330592,  0.06287656,  0.02079317],
       [ 0.58330592,  0.56287656,  0.02079317],
       [ 0.74997259,  0.3962099 ,  0.13308022],
       [ 0.74997259,  0.8962099 ,  0.13308022],
       [ 0.24997259,  0.3962099 ,  0.13308022],
       [ 0.24997259,  0.8962099 ,  0.13308022],
       [ 0.41899389,  0.22427639,  0.24349414],
       [ 0.92185849,  0.72681419,  0.2445969 ],
       [ 0.92211185,  0.22548399,  0.24483813],
       [ 0.41209504,  0.72118551,  0.24451221],
       [ 0.10123061,  0.05977886,  0.36005352],
       [ 0.59588392,  0.56240731,  0.35386542],
       [ 0.09125505,  0.55466019,  0.36622431],
       [ 0.59650079,  0.05224914,  0.354275  ]])

重新生成新的xsd文件


In [19]:
xsd.tofile('new.xsd')  # 当前路径下会生成新的xsd文件

In [10]:
ls


00-04.arc                   POSCAR
00-04.xtd                   POSCAR_freq
CONTCAR                     POTCAR
DOS_SUM                     Untitled.ipynb
ELFCAR                      XDATCAR
INCAR                       bulk.xsd
INCAR2                      ceo2-111.cif
KPOINTS                     fort.188
OSZICAR                     h_top_c_fcc_far.xsd
OSZICAR_md                  h_top_c_fcc_far_noname.xsd
OUT.ANI                     new.xsd
OUTCAR                      ts.xyz
OUTCAR_freq                 vasp.script
PLOTCON

笛卡尔坐标和分数坐标的相互转换


In [11]:
xsd.bases


Out[11]:
array([[  4.31035158,  -2.48858265,   0.        ],
       [  0.        ,   4.97716529,   0.        ],
       [  0.        ,   0.        ,  18.09575766]])

In [13]:
cart = xsd.dir2cart(xsd.bases, xsd.data)

In [14]:
cart


Out[14]:
array([[ 1.32452449,  0.05470107,  8.0651234 ],
       [ 3.19770379,  0.04995723,  7.67893041],
       [ 2.12325651,  0.08820902,  8.76428743],
       [ 0.35907782,  0.10563338,  0.37626824],
       [ 0.35907782,  2.59421603,  0.37626824],
       [ 2.51425361, -1.13865795,  0.37626824],
       [ 2.51425361,  1.3499247 ,  0.37626824],
       [ 3.23264554,  0.10563338,  2.40818746],
       [ 3.23264554,  2.59421602,  2.40818746],
       [ 1.07746975,  1.3499247 ,  2.40818746],
       [ 1.07746975,  3.83850735,  2.40818746],
       [ 1.80601096,  0.07355977,  4.40621097],
       [ 3.97353422,  1.3233533 ,  4.42616618],
       [ 3.97462628, -1.17248048,  4.43053138],
       [ 1.77627452,  2.56392691,  4.4246337 ],
       [ 0.43633953,  0.0456085 ,  6.51544117],
       [ 2.5684692 ,  1.31628775,  6.40346289],
       [ 0.39334134,  2.53353974,  6.62710637],
       [ 2.57112813, -1.22438893,  6.41087462]])

In [20]:
cart += 0.001  # 在笛卡尔坐标基础上都增加0.001

In [16]:
cart


Out[16]:
array([[ 1.32552449,  0.05570107,  8.0661234 ],
       [ 3.19870379,  0.05095723,  7.67993041],
       [ 2.12425651,  0.08920902,  8.76528743],
       [ 0.36007782,  0.10663338,  0.37726824],
       [ 0.36007782,  2.59521603,  0.37726824],
       [ 2.51525361, -1.13765795,  0.37726824],
       [ 2.51525361,  1.3509247 ,  0.37726824],
       [ 3.23364554,  0.10663338,  2.40918746],
       [ 3.23364554,  2.59521602,  2.40918746],
       [ 1.07846975,  1.3509247 ,  2.40918746],
       [ 1.07846975,  3.83950735,  2.40918746],
       [ 1.80701096,  0.07455977,  4.40721097],
       [ 3.97453422,  1.3243533 ,  4.42716618],
       [ 3.97562628, -1.17148048,  4.43153138],
       [ 1.77727452,  2.56492691,  4.4256337 ],
       [ 0.43733953,  0.0466085 ,  6.51644117],
       [ 2.5694692 ,  1.31728775,  6.40446289],
       [ 0.39434134,  2.53453974,  6.62810637],
       [ 2.57212813, -1.22338893,  6.41187462]])

转换回分数坐标


In [17]:
xsd.data = xsd.cart2dir(xsd.bases, cart)

In [18]:
xsd.data


Out[18]:
array([[ 0.3075212 ,  0.16495193,  0.44574665],
       [ 0.74209812,  0.38128726,  0.42440502],
       [ 0.49282674,  0.26433703,  0.48438356],
       [ 0.08353792,  0.06319348,  0.02084844],
       [ 0.08353792,  0.56319348,  0.02084844],
       [ 0.58353792,  0.06319348,  0.02084844],
       [ 0.58353792,  0.56319348,  0.02084844],
       [ 0.75020459,  0.39652682,  0.13313548],
       [ 0.75020459,  0.89652681,  0.13313548],
       [ 0.25020459,  0.39652681,  0.13313548],
       [ 0.25020459,  0.89652682,  0.13313548],
       [ 0.41922589,  0.22459331,  0.2435494 ],
       [ 0.92209049,  0.72713111,  0.24465216],
       [ 0.92234385,  0.22580091,  0.24489339],
       [ 0.41232704,  0.72150243,  0.24456747],
       [ 0.10146261,  0.06009577,  0.36010878],
       [ 0.59611592,  0.56272423,  0.35392068],
       [ 0.09148705,  0.55497711,  0.36627957],
       [ 0.59673279,  0.05256606,  0.35433027]])