Download AmberTools Users` Manual

Transcript
6.10 Looping over atoms in molecules
a and m represent an atom and a molecule variable. The action of the loop is to set a to each
atom in m in this order. The first atom is the first atom of the first residue of the first strand.
This is followed by the rest of the atoms of this residue, followed by the atoms of the second
residue, etc until all the atoms in the first strand have been visited. The process is then repeated
on the second and subsequent strands in m until a has been set to every atom in m. The order of
the strands in a molecule is the order in which they were created with addstrand(), the order of
the residues in a strand is the order in which they were added with addresidue() and the order
of the atoms in a residue is the order in which they are listed in the residue library entry that the
residue is based on.
The following program uses two nested for-in loops to compute all the proton-proton distances in a molecule. Distances less than cutoff are written to stdout. The program uses the
second argument on the command to hold the cutoff value. The program also uses the =∼ operator to compare a character string , in this case an atom name to pattern, specified as a regular
expression.
1
2
3
4
// Program 4 - compute H-H distances <= cutoff
molecule
m;
atom
ai, aj;
float
d, cutoff;
5
6
7
cutoff = atof( argv[ 2 ] );
m = getpdb( "gcg10.pdb" );
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
for( ai in m ){
if( ai.atomname !~ "H" )continue;
for( aj in m ){
if( aj.tatomnum <= ai.tatomnum )continue;
if( aj.atomname !~ "H" )continue;
if(( d=distp(ai.pos,aj.pos))<=cutoff){
printf(
"%3d %-4s %-4s %3d %-4s %-4s %8.3f\\n",
ai.tresnum, ai.resname, ai.atomname,
aj.tresnum, aj.resname, aj.atomname,
d );
}
}
}
The molecule is read into m using getpdb(). Two atom variables ai and aj are used to hold
the pairs of atoms. The outer loop in lines 9-22 sets ai to each atom in m in the order discussed
above. Since this program is only interested in proton-proton distances, if ai is not a proton, all
calculations involving that atom can be skipped. The if in line 10 tests to see if ai is a proton.
It does so by testing to see if ai’s name, available via the atomname attribute doesn’t match the
regular expression "H". If it doesn’t match then the program executes the continue statement
also on line 10, which has the effect of advancing the outer loop to its next atom.
>From the section on attributes, ai.atomname behaves like a character string. It can be compared against other character strings or tested to see if it matches a pattern or regular expression.
125