Hi,
I have installed cygwin in a vista platform and tried to run an awk script from the shell but I got an error message pointing that the single qoute as invalid character. Here is the codes I used:
#! /bin/sh
#
awk 'BEGIN {
xmin = 100000.
xmax = -100000.
ymin = 100000.
ymax = -100000.
zmin = 100000.
zmax = -100000.
xsum = 0.
ysum = 0.
zsum = 0.
xpoints = 0
ypoints = 0
zpoints = 0
atom_total = 0
add = 5.0
passo = 0.375
}
$1 ~ /ATOM|HETATM|atom|hetatm/ {
x[atom_total] = substr($0,31,8) + 0.
y[atom_total] = substr($0,39,8) + 0.
z[atom_total] = substr($0,47,8) + 0.
xsum += x[atom_total]
ysum += y[atom_total]
zsum += z[atom_total]
atom_total++
}
END {
if ( atom_total != 0 ) {
xmean = xsum / atom_total
ymean = ysum / atom_total
zmean = zsum / atom_total
#
# Loop over atoms in molecule to find the xyz-coordinates of
# the atom nearest the mean xyz-coordinates of the whole
# molecule...
#
dmin = 100000.
for (i=0; i<atom_total; i++) {
dx = x - xmean
dy = y - ymean
dz = z - zmean
d2 = dx*dx + dy*dy + dz*dz
if (d2 < dmin) {
dmin = d2
centralatom = i
}
if (x < xmin) {
xmin = x
}
if (x > xmax) {
xmax = x
}
if (y < ymin) {
ymin = y
}
if (y > ymax) {
ymax = y
}
if (z < zmin) {
zmin = z
}
if (z > zmax) {
zmax = z
}
}
dx_max = xmax - xmin
dy_max = ymax - ymin
dz_max = zmax - zmin
max = -100000
if (dx_max > max) {
max = dx_max
}
if (dy_max > max) {
max = dy_max
}
if (dz_max > max) {
max = dz_max
}
xmin -= max/2
ymin -= max/2
zmin -= max/2
xmax += max/2
ymax += max/2
zmax += max/2
#xmin -= add
#ymin -= add
#zmin -= add
#xmax += add
#ymax += add
#zmax += add
xpoints = (xmax-xmin)/passo
ypoints = (ymax-ymin)/passo
zpoints = (zmax-zmin)/passo
printf("=========================== Cut from the line below ========================\n")
printf("REMARK Box file to be displayed in any molecule visualizer\n")
printf("REMARK Atoms 1-8 are the vertex of the box\n")
printf("REMARK Atom 9 is the center of the box\n")
printf("REMARK gridcenter %.3f %.3f %.3f\t#xyz-coordinates or \"auto\"\n", xmean, ymean, zmean)
printf("REMARK npts %d %d %d\t\t\t# num.grid points in xyz\n", xpoints, ypoints, zpoints)
printf("REMARK\n")
printf("HETATM 1 C BOX 1 %7.3f %7.3f %7.3f\n", xmin,ymax,zmax)
printf("HETATM 2 C BOX 1 %7.3f %7.3f %7.3f\n", xmax,ymax,zmax)
printf("HETATM 3 C BOX 1 %7.3f %7.3f %7.3f\n", xmin,ymin,zmax)
printf("HETATM 4 C BOX 1 %7.3f %7.3f %7.3f\n", xmax,ymin,zmax)
printf("HETATM 5 C BOX 1 %7.3f %7.3f %7.3f\n", xmin,ymax,zmin)
printf("HETATM 6 C BOX 1 %7.3f %7.3f %7.3f\n", xmax,ymax,zmin)
printf("HETATM 7 C BOX 1 %7.3f %7.3f %7.3f\n", xmin,ymin,zmin)
printf("HETATM 8 C BOX 1 %7.3f %7.3f %7.3f\n", xmax,ymin,zmin)
printf("HETATM 9 C BOX 1 %7.3f %7.3f %7.3f\n", xmean, ymean, zmean)
printf("CONECT 1 5 3 2\n")
printf("CONECT 2 1 4 6\n")
printf("CONECT 3 1 4 7\n")
printf("CONECT 4 3 2 8\n")
printf("CONECT 5 1 6 7\n")
printf("CONECT 6 5 2 8\n")
printf("CONECT 7 5 3 8\n")
printf("CONECT 8 4 6 7\n")
printf("END\n")
printf("=========================== to the line previous this one ========================\n")
printf("\n")
printf("\n")
printf("\n")
printf("\t\t ... and paste into a text file named box.pdb\n")
}
}' $1
and here is the error message that I recieved:
awk: awk 'BEGIN {
awk: awk ^ invalid char ''' in expression
I tried to change the single qoute to double qoute at the beginning and the end of the script but it ended up with an error like this:
awk: awk "BEGIN {
awk: awk ^ unterminated string
Am I missing something or done anything wrong in the code?
Thanks.
I have installed cygwin in a vista platform and tried to run an awk script from the shell but I got an error message pointing that the single qoute as invalid character. Here is the codes I used:
#! /bin/sh
#
awk 'BEGIN {
xmin = 100000.
xmax = -100000.
ymin = 100000.
ymax = -100000.
zmin = 100000.
zmax = -100000.
xsum = 0.
ysum = 0.
zsum = 0.
xpoints = 0
ypoints = 0
zpoints = 0
atom_total = 0
add = 5.0
passo = 0.375
}
$1 ~ /ATOM|HETATM|atom|hetatm/ {
x[atom_total] = substr($0,31,8) + 0.
y[atom_total] = substr($0,39,8) + 0.
z[atom_total] = substr($0,47,8) + 0.
xsum += x[atom_total]
ysum += y[atom_total]
zsum += z[atom_total]
atom_total++
}
END {
if ( atom_total != 0 ) {
xmean = xsum / atom_total
ymean = ysum / atom_total
zmean = zsum / atom_total
#
# Loop over atoms in molecule to find the xyz-coordinates of
# the atom nearest the mean xyz-coordinates of the whole
# molecule...
#
dmin = 100000.
for (i=0; i<atom_total; i++) {
dx = x - xmean
dy = y - ymean
dz = z - zmean
d2 = dx*dx + dy*dy + dz*dz
if (d2 < dmin) {
dmin = d2
centralatom = i
}
if (x < xmin) {
xmin = x
}
if (x > xmax) {
xmax = x
}
if (y < ymin) {
ymin = y
}
if (y > ymax) {
ymax = y
}
if (z < zmin) {
zmin = z
}
if (z > zmax) {
zmax = z
}
}
dx_max = xmax - xmin
dy_max = ymax - ymin
dz_max = zmax - zmin
max = -100000
if (dx_max > max) {
max = dx_max
}
if (dy_max > max) {
max = dy_max
}
if (dz_max > max) {
max = dz_max
}
xmin -= max/2
ymin -= max/2
zmin -= max/2
xmax += max/2
ymax += max/2
zmax += max/2
#xmin -= add
#ymin -= add
#zmin -= add
#xmax += add
#ymax += add
#zmax += add
xpoints = (xmax-xmin)/passo
ypoints = (ymax-ymin)/passo
zpoints = (zmax-zmin)/passo
printf("=========================== Cut from the line below ========================\n")
printf("REMARK Box file to be displayed in any molecule visualizer\n")
printf("REMARK Atoms 1-8 are the vertex of the box\n")
printf("REMARK Atom 9 is the center of the box\n")
printf("REMARK gridcenter %.3f %.3f %.3f\t#xyz-coordinates or \"auto\"\n", xmean, ymean, zmean)
printf("REMARK npts %d %d %d\t\t\t# num.grid points in xyz\n", xpoints, ypoints, zpoints)
printf("REMARK\n")
printf("HETATM 1 C BOX 1 %7.3f %7.3f %7.3f\n", xmin,ymax,zmax)
printf("HETATM 2 C BOX 1 %7.3f %7.3f %7.3f\n", xmax,ymax,zmax)
printf("HETATM 3 C BOX 1 %7.3f %7.3f %7.3f\n", xmin,ymin,zmax)
printf("HETATM 4 C BOX 1 %7.3f %7.3f %7.3f\n", xmax,ymin,zmax)
printf("HETATM 5 C BOX 1 %7.3f %7.3f %7.3f\n", xmin,ymax,zmin)
printf("HETATM 6 C BOX 1 %7.3f %7.3f %7.3f\n", xmax,ymax,zmin)
printf("HETATM 7 C BOX 1 %7.3f %7.3f %7.3f\n", xmin,ymin,zmin)
printf("HETATM 8 C BOX 1 %7.3f %7.3f %7.3f\n", xmax,ymin,zmin)
printf("HETATM 9 C BOX 1 %7.3f %7.3f %7.3f\n", xmean, ymean, zmean)
printf("CONECT 1 5 3 2\n")
printf("CONECT 2 1 4 6\n")
printf("CONECT 3 1 4 7\n")
printf("CONECT 4 3 2 8\n")
printf("CONECT 5 1 6 7\n")
printf("CONECT 6 5 2 8\n")
printf("CONECT 7 5 3 8\n")
printf("CONECT 8 4 6 7\n")
printf("END\n")
printf("=========================== to the line previous this one ========================\n")
printf("\n")
printf("\n")
printf("\n")
printf("\t\t ... and paste into a text file named box.pdb\n")
}
}' $1
and here is the error message that I recieved:
awk: awk 'BEGIN {
awk: awk ^ invalid char ''' in expression
I tried to change the single qoute to double qoute at the beginning and the end of the script but it ended up with an error like this:
awk: awk "BEGIN {
awk: awk ^ unterminated string
Am I missing something or done anything wrong in the code?
Thanks.