Python wrapper for running instances of trisurf-ng
Samo Penic
2018-05-24 5e1956510b43a1cdb184cc99b186d573f5227f00
commit | author | age
a4f8eb 1 from ctypes import *
SP 2
3 TS_SUCCESS=0
4 TS_FAIL=1
5
6 TS_ID_FILAMENT=1
7
8 TS_COORD_CARTESIAN=0
9 TS_COORD_SPHERICAL=1
10 TS_COORD_CYLINDRICAL=2
11
12
13 class ts_coord(Structure):
14     _fields_=[
15         ("e1", c_double),
16         ("e2", c_double),
17         ("e3", c_double),
18         ("coord_type", c_uint)
19         ]
20 class ts_vertex(Structure):
21     pass
22 class ts_bond(Structure):
23     pass
24 class ts_triangle(Structure):
25     pass
26 class ts_cell(Structure):
27     pass
28 class ts_poly(Structure):
29     pass
30 class ts_cluster(Structure):
31     pass
32 ts_vertex._fields_=[
33         ('idx',c_uint),
34         ('x',c_double),
35         ('y',c_double),
36         ('z',c_double),
37         ('neigh_no',c_uint),
38         ('neigh', POINTER(POINTER(ts_vertex))),
39         ('bond_length', POINTER(c_double)),
40         ('bond_length_dual',POINTER(c_double)),
41         ('curvature', c_double),
42         ('energy', c_double),
43         ('energy_h',c_double),
44         ('tristar_no', c_uint),
45         ('tristar', POINTER(POINTER(ts_triangle))),
46         ('bond_no',c_uint),
47         ('bond',POINTER(POINTER(ts_bond))),
48         ('cell',POINTER(ts_cell)),
49         ('xk',c_double),
50         ('c',c_double),
51         ('id', c_uint),
52         ('projArea',c_double),
53         ('relR', c_double),
54         ('solAngle', c_double),
55         ('grafted_poly', POINTER(ts_poly)),
56         ('cluster',POINTER(ts_cluster)),
57         ]
58 class ts_vertex_list(Structure):
59     _fields_=[('n',c_uint), ('vtx',POINTER(POINTER(ts_vertex)))]
60
61 ts_bond._fields_=[('idx',c_uint),
62         ('vtx1', POINTER(ts_vertex)),
63         ('vtx2', POINTER(ts_vertex)),
64         ('bond_length',c_double),
65         ('bond_length_dual',c_double),
66         ('tainted', c_char),
67         ('energy',c_double),
68         ('x',c_double),
69         ('y',c_double),
70         ('z',c_double),
71     ]
72 class ts_bond_list(Structure):
73     _fields_=[('n', c_uint),('bond',POINTER(POINTER(ts_bond)))]
74
75 ts_triangle._fields_=[
76         ('idx',c_uint),
77         ('vertex', POINTER(ts_vertex)*3),
78         ('neigh_no',c_uint),
79         ('neigh', POINTER(POINTER(ts_triangle))),
80         ('xnorm', c_double),
81         ('ynorm', c_double),
82         ('znorm', c_double),
83         ('area', c_double),
84         ('volume', c_double),
7ad2b4 85         ('energy', c_double),
a4f8eb 86     ]
SP 87
88 class ts_triangle_list(Structure):
5e1956 89     _fields_=[('n',c_uint),('a0',c_double),('tria', POINTER(POINTER(ts_triangle))),]
a4f8eb 90
SP 91
92 ts_cell._fields_=[
93     ('idx', c_uint),
94     ('vertex', POINTER(POINTER(ts_vertex))),
95     ('nvertex', c_uint),
96     ]        
97
98 class ts_cell_list(Structure):
99     _fields_=[
100         ('ncmax', c_uint*3),
101         ('cellno', c_uint),
102         ('cell',POINTER(POINTER(ts_cell))),
103         ('dcell', c_double),
104         ('shift', c_double),
105         ('max_occupancy', c_double),
106         ('dmin_interspecies', c_double)
107     ]
108
109 class ts_spharm(Structure):
110     _fields_=[
111         ('l',c_uint),
112         ('ulm', POINTER(POINTER(c_double))),
113     #    ('ulmComplex', POINTER(POINTER(gsl_complex))), #poisci!!!!
114         ('ulmComplex', POINTER(POINTER(c_double))), #temporary solution
115         ('sumUlm2', POINTER(POINTER(c_double))),
116         ('N', c_uint),
117         ('co',POINTER(POINTER(c_double))),
118         ('Ylmi', POINTER(POINTER(c_double))),
119         ]
120
121 ts_poly._fields_=[
122         ('vlist', POINTER(ts_vertex_list)),
123         ('blist', POINTER(ts_bond_list)),
124         ('grafted_vtx',POINTER(ts_vertex)),
125         ('k', c_double),
126     ]
127
128 class ts_poly_list(Structure):
129     _fields_=[('n',c_uint),('poly',POINTER(POINTER(ts_poly)))]
130
131 class ts_tape(Structure):
132     _fields_=[
133         ('nshell',c_long),
134         ('ncxmax',c_long),
135         ('ncymax',c_long),
136         ('nczmax',c_long),
137         ('npoly',c_long),
138         ('nmono',c_long),
139         ('internal_poly',c_long),
140         ('nfil',c_long),
141         ('nfono', c_long),
142         ('R_nucleus',c_long),
143         ('R_nucleusX',c_double),
144         ('R_nucleusY',c_double),
145         ('R_nucleusZ',c_double),
146         ('pswitch',c_long),
147         ('constvolswitch',c_long),
148         ('constareaswitch',c_long),
7ad2b4 149         ('stretchswitch',c_long),
SP 150         ('xkA0',c_double),
a4f8eb 151         ('constvolprecision',c_double),
SP 152         ('multiprocessing',c_char_p),
153         ('brezveze0',c_long),
154         ('brezveze1',c_long),
155         ('brezveze2',c_long),
156         ('xk0',c_double),
157         ('dmax',c_double),
158         ('dmin_interspecies',c_double),
159         ('stepsize',c_double),
160         ('kspring',c_double),
161         ('xi',c_double),
162         ('pressure',c_double),
163         ('iterations',c_long),
164         ('inititer',c_long),
165         ('mcsweeps',c_long),
166         ('quiet',c_long),
167         ('shc',c_long),
168         ('number_of_vertice_with_c0',c_long),
169         ('c0', c_double),
170         ('w', c_double),
171         ('F', c_double),
172     ]
173         
174
175 class ts_vesicle(Structure):
176     _fields_=[
177         ('vlist', POINTER(ts_vertex_list)),
178         ('blist', POINTER(ts_bond_list)),
179         ('tlist', POINTER(ts_triangle_list)),
180         ('clist', POINTER(ts_cell_list)),
181         ('nshell', c_uint),
182         ('bending_rigidity',c_double),
183         ('dmax',c_double),
184         ('stepsize',c_double),
185         ('cm', c_double*3),
186         ('volume', c_double),
187         ('sphHarmonics',POINTER(ts_spharm)),
188         ('poly_list', POINTER(ts_poly_list)),
189         ('filament_list', POINTER(ts_poly_list)),
190         ('spring_constant', c_double),
191         ('pressure', c_double),
192         ('pswitch', c_int),
193         ('tape', POINTER(ts_tape)),
194         ('R_nucleus', c_double),
195         ('R_nucleusX', c_double),
196         ('R_nucleusY', c_double),
197         ('R_nucleusZ', c_double),
198         ('nucleus_center', c_double *3 ),
199         ('area', c_double),
200     ]
201
202 ts_cluster._fields_=[('nvtx',c_uint),('idx',c_uint),('vtx', POINTER(POINTER(ts_vertex)))]
203
204 class ts_cluster_list(Structure):
a2f057 205     _fields_=[('n',c_uint),('cluster',POINTER(POINTER(ts_cluster)))]
a4f8eb 206
83999e 207
SP 208
209
210 ts=CDLL('libtrisurf.so')
a8e8b1 211
SP 212
213
214 #function call wrappers
215 def create_vesicle_from_tape(tape):
216     """Using pointer for tape, it creates a vesicle, returning pointer to it."""
217     ts.create_vesicle_from_tape.argtype=POINTER(ts_tape)
218     ts.create_vesicle_from_tape.restype=POINTER(ts_vesicle)
219     return ts.create_vesicle_from_tape(tape)
220
221 def parsetape(filename='tape'):
222     """Loads tape with  filename (if not given it defaults to 'tape'). It returns a pointer to structure for tape"""
223     ts.parsetape.restype=POINTER(ts_tape)
224     ts.parsetape.argtype=[c_char_p]
225     return ts.parsetape(filename.encode('ascii'))
226
227 def parseDump(filename):
228     """Loads a vtu file with 'filename' and creates a vesicle returning pointer to it"""
229     ts.parseDump.argtype=[c_char_p]
230     ts.parseDump.restype=POINTER(ts_vesicle)
231     vesicle=ts.parseDump(filename.encode('ascii'))
232     return vesicle
233
234 def single_timestep(vesicle):
235     """Makes a single timestep in simulations. Returns a tuple of vmsrt and bfrt (vertex move success rate and bond flip success rate)"""
236     ts.single_timestep.argtype=[POINTER(ts_vesicle),POINTER(c_double),POINTER(c_double)]
237     vmsrt=c_double(0.0)
238     bfsrt=c_double(0.0)
239     ts.single_timestep(vesicle,byref(vmsrt),byref(bfsrt))
240     return (vmsrt.value, bfsrt.value)
241
242 def write_vertex_xml_file(vesicle,timestep_no=0):
243     """Writes a vesicle into file with filename 'timestep_XXXXXX.vtu', where XXXXXX is a leading zeroed number given with timestep_no parameter (defaults to 0 if not given"""
244     ts.write_vertex_xml_file.argtypes=[POINTER(ts_vesicle),c_int]
245     ts.write_vertex_xml_file(vesicle,c_int(timestep_no))
246
247
248 def vesicle_free(vesicle):
249     """Free memory of the whole vesicle"""
250     ts.vesicle_free.argtype=[POINTER(ts_vesicle)]
251     ts.vesicle_free(vesicle)
252
a2f057 253 def vesicle_volume(vesicle):
SP 254     ts.vesicle_volume.argtype=[POINTER(ts_vesicle)]
255     ts.vesicle_volume(vesicle)
a8e8b1 256
a2f057 257 def vesicle_area(vesicle):
SP 258     ts.vesicle_area.argtype=[POINTER(ts_vesicle)]
259     ts.vesicle_area(vesicle)
a8e8b1 260
a2f057 261 def gyration_eigen(vesicle):
SP 262     ts.gyration_eigen.argtype=[POINTER(ts_vesicle), POINTER(c_double), POINTER(c_double), POINTER(c_double)]
263     l1=c_double(0.0)
264     l2=c_double(0.0)
265     l3=c_double(0.0)
266     ts.gyration_eigen(vesicle , byref(l1), byref(l2), byref(l3))
267     return (l1.value, l2.value, l3.value)
268
269 def vesicle_meancurvature(vesicle):
270     ts.vesicle_meancurvature.argtype=[POINTER(ts_vesicle)]
271     ts.vesicle_meancurvature.restype=c_double
272     return ts.vesicle_meancurvature(vesicle)
273
274 def init_cluster_list():
275     ts.init_cluster_list.restype=POINTER(ts_cluster_list)
276     ret=ts.init_cluster_list()
277     return ret
278
279 def clusterize_vesicle(vesicle, cluster_list):
280     ts.clusterize_vesicle.argtype=[POINTER(ts_vesicle), POINTER(ts_cluster_list)]
281     ts.clusterize_vesicle(vesicle, cluster_list)
282
283 def cluster_list_free(cluster_list):
284     """Free memory of cluster list"""
285     ts.cluster_list_free.argtype=[POINTER(ts_cluster_list)]
286     ts.cluster_list_free(cluster_list)
287
5e1956 288 def stretchenergy(vesicle, triangle):
SP 289     ts.stretchenergy.argtype=[POINTER(ts_vesicle), POINTER(ts_triangle)]
290     ts.stretchenergy(vesicle,triangle)
291
a2f057 292     
SP 293