File: bohr2ang.py

package info (click to toggle)
lammps 20250204%2Bdfsg.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 474,368 kB
  • sloc: cpp: 1,060,070; python: 27,785; ansic: 8,956; f90: 7,254; sh: 6,044; perl: 4,171; fortran: 2,442; xml: 1,714; makefile: 1,352; objc: 238; lisp: 188; yacc: 58; csh: 16; awk: 14; tcl: 6; javascript: 2
file content (74 lines) | stat: -rw-r--r-- 2,023 bytes parent folder | download | duplicates (10)
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
Info="""
Module name: bohr2ang.py 

Author: (c) Andres Jaramillo-Botero
California Institute of Technology
ajaramil@caltech.edu
Project: pEFF
Version: August 2009

Usage: python bohr2ang.py
>>Name of data file (bohr): [datafile]

Results:
creates a datafile with extension .ang in real units

"""
import os

currdir=os.getcwd()
datafile=raw_input("Name of data file (bohr): ")
bohr2ang=0.529177249
bperatu2angperfs=0.512396271120794
f=open(currdir+'/'+datafile,'r')
w=open(currdir+'/'+datafile+'.ang','w')
lines=f.readlines()
atom_flag=False
vel_flag=False
for line in lines:
  if line.find("xlo") > 0:
    parse=line.split()
    w.write("%f %f xlo xhi\n"%(float(parse[0])*bohr2ang,float(parse[1])*bohr2ang))
  elif line.find("ylo") > 0:
    parse=line.split()
    w.write("%f %f ylo yhi\n"%(float(parse[0])*bohr2ang,float(parse[1])*bohr2ang))
  elif line.find("zlo") > 0:
    parse=line.split()
    w.write("%f %f zlo zhi\n"%(float(parse[0])*bohr2ang,float(parse[1])*bohr2ang))
  elif line.find("xy") >= 0:
    parse=line.split()
    w.write("%f %f %f xy xz yz\n"%(float(parse[0])*bohr2ang,float(parse[1])*bohr2ang,float(parse[2])*bohr2ang))
  elif atom_flag and line.strip():
    parse=line.split()
    id=parse[0]
    type=parse[1]
    q=parse[2]
    spin=parse[3]
    eradius=float(parse[4])*bohr2ang
    x=float(parse[5])*bohr2ang
    y=float(parse[6])*bohr2ang
    z=float(parse[7])*bohr2ang
    rest=" ".join(parse[8:])
    w.write("%s %s %s %s %f %f %f %f %s\n"%(id,type,q,spin,eradius,x,y,z,rest))
  elif line.find("Atoms") >= 0:
    w.write(line)
    atom_flag=True
    continue
  elif vel_flag and line != "\n":
    parse=line.split()
    id=parse[0]
    vx=float(parse[1])*bperatu2angperfs
    vy=float(parse[2])*bperatu2angperfs
    vz=float(parse[3])*bperatu2angperfs
    erv=float(parse[4])*bperatu2angperfs
    w.write("%s %f %f %f\n"%(id,vx,vy,vz,erv))
  elif line.find("Velocities") >= 0:
    w.write(line)
    atom_flag=False
    vel_flag=True
    continue
  else:
    w.write(line)

f.close()
w.close()