Project

General

Profile

checkmass.py

Roland Schulz, 06/15/2014 04:57 AM

 
1
from glob import glob
2

    
3
debug=False
4

    
5
mass={} #dict by atomtype
6
mass2={} #dict by rounded mass
7
for l in file("atomtypes.atp"):
8
    if l.startswith(";"): continue
9
    ll=l.split()
10
    m=float(ll[1])
11
    mass[ll[0]]=m
12
    if round(m) in mass2:
13
        if mass2[round(m)]!=m and debug:
14
            print "different masses %s and %s for %s"%(m,mass2[round(m)],ll[0])
15
    else:
16
        mass2[round(m)]=m
17

    
18
for f in glob("*tdb"):
19
    inside=False
20
    for l in file(f):
21
        if l.rstrip() == "[ replace ]": 
22
            inside=True
23
        elif l.startswith("["):
24
            inside=False
25
        elif inside:
26
            l=l[:l.find(";")]
27
            t,m=l.split()[-3:-1]
28
            m=float(m)
29
            if not t in mass:
30
                print "type %s missing"%(t,)
31
            elif mass[t]!=m:
32
                print t,m,mass[t]
33
    
34