Commit fe01e1b1 authored by Matthias Schroeder's avatar Matthias Schroeder

changed elements to static list

parent 19ddca27
......@@ -9,7 +9,7 @@ FILEPAT = "mol_%04d"
OUTDIR = 'masses/'
# description of elements
elements = [
elements = (
{ "formel":'C' , "weight": 12 , "min":1, "max":167, "val": 4, "spec": 0 },
{ "formel":'C13' , "weight": 13.003354835 , "min":0, "max": 3, "val": 4, "spec": 0 },
{ "formel":'H' , "weight": 1.0078250 , "min":1, "max":800, "val": 1, "spec": 0 },
......@@ -20,21 +20,21 @@ elements = [
{ "formel":'S' , "weight": 31.972072 , "min":0, "max": 30, "val": 6, "spec": 0 },
{ "formel":'S34' , "weight": 33.96786690 , "min":0, "max": 1, "val": 6, "spec": 0 },
{ "formel":'P' , "weight": 30.973763 , "min":0, "max": 20, "val": 5, "spec": 0 },
# { "formel":'Cui' , "weight": 62.92959772 , "min":0, "max": 2, "val": 1, "spec": 1 },
# { "formel":'Cuii' , "weight": 62.92959772 , "min":0, "max": 2, "val": 2, "spec": 1 },
# { "formel":'Feii' , "weight": 55.934936 , "min":0, "max": 2, "val": 2, "spec": 1 },
# { "formel":'FEiii', "weight": 55.934936 , "min":0, "max": 2, "val": 3, "spec": 1 },
# { "formel":'BR79' , "weight": 78.918338 , "min":0, "max": 2, "val": 1, "spec": 1 },
# { "formel":'BR81' , "weight": 80.91690 , "min":0, "max": 2, "val": 1, "spec": 1 },
# { "formel":'CL' , "weight": 34.9688527 , "min":0, "max": 2, "val": 1, "spec": 1 },
# { "formel":'Na' , "weight": 22.98976928 , "min":0, "max": 2, "val": 1, "spec": 1 },
# { "formel":'Ni.ii', "weight": 57.9353462 , "min":0, "max": 2, "val": 2, "spec": 1 },
# { "formel":'Znii' , "weight": 65.38 , "min":0, "max": 2, "val": 2, "spec": 1 },
# { "formel":'I' , "weight": 126.90447 , "min":0, "max": 2, "val": 1, "spec": 1 },
]
for i in range(len(elements)):
if elements[i]['max']>10:
elements[i]['max'] = 10
{ "formel":'Cl' , "weight": 34.9688527 , "min":0, "max": 2, "val": 1, "spec": 1 },
{ "formel":'Cui' , "weight": 62.92959772 , "min":0, "max": 2, "val": 1, "spec": 1 },
{ "formel":'Cuii' , "weight": 62.92959772 , "min":0, "max": 2, "val": 2, "spec": 1 },
{ "formel":'Feii' , "weight": 55.934936 , "min":0, "max": 2, "val": 2, "spec": 1 },
{ "formel":'FEiii', "weight": 55.934936 , "min":0, "max": 2, "val": 3, "spec": 1 },
{ "formel":'BR79' , "weight": 78.918338 , "min":0, "max": 2, "val": 1, "spec": 1 },
{ "formel":'BR81' , "weight": 80.91690 , "min":0, "max": 2, "val": 1, "spec": 1 },
{ "formel":'Na' , "weight": 22.98976928 , "min":0, "max": 2, "val": 1, "spec": 1 },
{ "formel":'Ni.ii', "weight": 57.9353462 , "min":0, "max": 2, "val": 2, "spec": 1 },
{ "formel":'Znii' , "weight": 65.38 , "min":0, "max": 2, "val": 2, "spec": 1 },
{ "formel":'I' , "weight": 126.90447 , "min":0, "max": 2, "val": 1, "spec": 1 },
)
LE= len(elements)
# create outdir if not exists
if not os.path.isdir(OUTDIR):
os.mkdir(OUTDIR)
......@@ -44,6 +44,15 @@ idx= {}
for i in range(len(elements)):
idx[elements[i]['formel']] = i
for i in range(len(elements)):
if elements[i]['max']>10:
elements[i]['max'] = 10
if elements[i]['spec'] == 1:
elements[i]['max'] = 0
elements[idx['P']]['max'] = 0
elements[idx['S34']]['max'] = 0
elements[idx['C13']]['max'] = 0
# prepare some arrays
moltype = np.dtype([('strct', np.int16, len(elements)), ('weight', np.float64)])
mols= np.ndarray(shape=(MAX_MASS,LINES_MOL), dtype=moltype)
......@@ -59,12 +68,12 @@ def check_strct(s,w):
# Valence check
val = 0
specs = 0
for i in range(len(elements)):
for i in range(LE):
val += s[i] * elements[i]['val']
if elements[i]['spec'] == 1:
specs += s[i]
if val % 2 ~= 0:
if val % 2 == 1:
return False
if specs > 2:
......@@ -97,7 +106,7 @@ def check_strct(s,w):
def format_strct(s):
""" Formats molecule in a nice way """
m=''
for i in range(len(elements)):
for i in range(LE):
if s[0][i]>0:
m += elements[i]['formel'] + '_' + str(s[0][i]) + ' '
return "%16.10f\t%s" % (s[1], m)
......@@ -105,7 +114,7 @@ def format_strct(s):
def calc_weight(s):
""" return total weight of molekule descripte by s """
w=0
for i in range(len(elements)):
for i in range(LE):
w= w + s[i] * elements[i]['weight']
return w
......@@ -116,6 +125,7 @@ def flush_mass(w):
if posi[w]>0:
filename= FILEPAT % w
print("Filename %s, cnt=%d" % (filename,posi[w]))
return
f = open(os.path.join(OUTDIR, filename), 'a')
for l in range(posi[w]):
f.write(format_strct(mols[w][l]) + "\n")
......@@ -140,7 +150,7 @@ if __name__ == "__main__":
# build next molecule
inc_done = False
for i in range(len(elements)):
for i in range(LE):
if strct[i]>=elements[i]['max']:
# hit top, -> fall down and continue to increment next position
strct[i]=elements[i]['min']
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment