convert script awk in python

alberto voodoo.bender at gmail.com
Tue Mar 23 07:32:17 EDT 2021


Hi to everyone I have an awk script that calculate minimum distances between points 

## atom type frag - atom type surface
#!/bin/bash

FILE1=$1.lammpstrj

if [ -f $FILE1 ];
then

awk 'function sq(x) {
    return x * x;
}
function dist(x1, y1, z1, x2, y2, z2) {
    return sqrt(sq(x1 - x2) + sq(y1 - y2) + sq(z1 - z2));
}
function print_distances() {
    if (na == 0)
        print "No type 8 atoms.";
    else {
        min = 1000;
        for (a = 0; a < na; a++) {
            d = dist(x, y, z, pos[a,"x"], pos[a,"y"], pos[a,"z"]);
#            printf "%7.5f ", d;
            if (d < min) min = d;
        }
        printf "%6i    %7.5f\n", istep, min;
        x = y = z = 0;
        delete pos;
        na = 0;
    }
}
$1 == 113 {
    if (x || y || z)
        print "More than one type $8 atom.";
    else {
        x = $2; y = $3; z = $4;
        istep++;
    }
}
$8 == 10 {
    pos[na,"x"] = $2; pos[na,"y"] = $3; pos[na,"z"] = $4;
    na += 1;
}
/^ITEM: ATOMS/ && na != 0 { print_distances(); }
END                       { print_distances(); }
' $1.lammpstrj > $1_mindist.txt
fi

where $1 is a particular atom and $8 is a other type of atoms

How could I prepare  a python script 

regards

A


More information about the Python-list mailing list