Extract value and average

MRAB python at mrabarnett.plus.com
Mon Jun 8 18:21:38 CEST 2009


Francesco Pietra wrote:
> I come 'naked', which is unusual and unfair. However, I find it
> difficult to give a correct start. The files consist, among other
> things, of a huge number of blocks of the type
> 
> 
>  NSTEP =     1000   TIME(PS) =     152.000  TEMP(K) =   298.54  PRESS =    89.4
>  Etot   =   -134965.2123  EKtot   =     41282.1781  EPtot      =   -176247.3905
>  BOND   =      1771.7644  ANGLE   =      6893.3003  DIHED      =      4660.1650
>  1-4 NB =      1931.6071  1-4 EEL =      7799.8343  VDWAALS    =     19047.1551
>  EELEC  =   -218354.9960  EHBOND  =         0.0000  RESTRAINT  =         3.7793
>  EAMBER (non-restraint)  =   -176251.1698
>  EKCMT  =     16048.2253  VIRIAL  =     14755.8154  VOLUME     =    669299.5681
>                                                     Density    =         0.9896
>  Ewald error estimate:   0.8252E-05
> 
> 
> 
> (in attachment what surely is a correct reproduction of columns)
> 
> I would like to extract values corresponding to variable DIHED (here
> 4660.1650) and getting also the mean value from all DIHED.
> 
> Thanks for giving a possible attack
> 
The first thing that comes to mind is a regular expression to extract
the DIHED values from the file contents, something like:

pattern = re.compile(r'DIHED\s+=\s+(\d+\.\d+)')




More information about the Python-list mailing list