-
Notifications
You must be signed in to change notification settings - Fork 1
/
simulations.py
102 lines (93 loc) · 3.22 KB
/
simulations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import importlib as port
import statevector as sv
utils=port.import_module('utils.utes')
k=port.import_module('kernels2')
import KMC
import sys
import copy
from shutil import copyfile
import os
import plistlib as pll
from abc import ABC,abstractmethod, ABCMeta, abstractproperty, abstractproperty
class ModelInterface(ABC):
def __init__(self):
self.mechanisms=None
@abstractmethod
def model_mechanisms(self):
print(self.mechanisms)
class my_model:
def __init__(self,*args,**kwargs):
self.params=None
self.load_config()
print("my model prms",self.params)
self.rates=self.params['rates']
print("my model rts",self.rates)
self.proteins=self.params['proteins']
self.nc=self.proteins['nucleus']
self.output_files=self.params['simulation']['outputs']
self.M=self.proteins['monomers']
self.state=sv.StateVector(self.M,delete_zeros=True)
self.model=KMC.Model(self.state,self.nc)
add=k.MonomerAddition(self.rates[0],self.nc)
sub=k.MonomerSubtraction(self.rates[1],self.nc)
nuc=k.Nucleation(self.rates[4],self.nc)
frag=k.Fragmentation(self.rates[4],self.nc)
coag=k.Coagulation(self.rates[3],self.nc)
# print(self.state)
self.model.add_propensity(add)
self.model.add_propensity(sub)
self.model.add_propensity(nuc)
self.model.add_propensity(frag)
self.model.add_propensity(coag)
self.model.add_mechanisms(sv.SmoluchowskiModel(self.state,self.nc))
print("my model model",self.model)
def getModel(self):
return self.model
def load_config(self):
self.params=load_config()
def load_config():
params=utils.load_config(utils.wd()+'/utils/input.data')
return params
class StateSimulation:
def __init__(self):
the_model=my_model()
self.model=the_model.getModel()
print("SS model",self.model)
self.fn=sys.argv[1]
self.path=utils.wd()+'/results/'+self.fn+'/'
def simulate(self):
for i in range(int(sys.argv[2])):
looping=True
countr=0
while(looping):
countr+=1
self.model.calculate_probability()
self.model.choose()
self.model.time_step()
self.model.advance()
# print(x)
#inp=input("0 to quit: ")
# if inp=="0":
# looping=False
# if inp=="1":
# print(self.model.data)
if countr>300:
looping = False
path=copy.copy(self.path)
fn=copy.copy(self.fn)
os.makedirs(path, exist_ok=True)
self.model.save(path+fn+str(i)+'.json')
self.model=my_model().getModel()
def __call__(self):
self.simulate()
if __name__ == '__main__':
sim=StateSimulation()
#sim()
# x=sv.StateVector([500],delete_zeros=True)
# self.model=KMC.Model(x,3)
# self.model.add_propensity(add)
# self.model.add_propensity(sub)
# self.model.add_propensity(nuc)
# self.model.add_propensity(frag)
# self.model.add_propensity(coag)
# self.model.add_mechanisms(sv.SmoluchowskiModel(x,3))