in reply to calculate distance between atoms and a target atom
Secondly, regular expressions offer a convenient method to capture specific parts of input. This allows one to write, e.g. @Zn = ($1, $2, $3); — but you must include (...) groups in the pattern. If the data is of rigidly fixed format, pack() and unpack() are often quite useful:
Note that the above example looks a bit strange because of the mixed regex and unpack usage. The second regex here combines three patterns from original code. @Atoms is an array of arrays (AoA). You can check the number of points with int(@Atoms).my $xyz_fmt = '@30a7 @38a6 @46a6'; while ($pdbline = <IN>) { if ($pdbline =~ m/ZN1 LG1 X/) { @Zn = unpack $xyz_fmt, $pdbline; next; } if ($pdbline =~ /^ATOM.*(OD2 ASP|NE2 HIS)/) { push @Atoms, [unpack $xyz_fmt, $pdbline]; ... } } # ... do the calculations once we have all data.
Update: for questions regarding the handling of AoA, please see perllol or perldsc.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: calculate distance between atoms and a target atom
by mishimakaz (Initiate) on Dec 03, 2013 at 18:16 UTC | |
by mishimakaz (Initiate) on Dec 03, 2013 at 20:54 UTC |