| 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), | |
| 85 | ] | |
| 86 | ||
| 87 | class ts_triangle_list(Structure): | |
| 88 | _fields_=[('n',c_uint),('tria', POINTER(POINTER(ts_triangle)))] | |
| 89 | ||
| 90 | ||
| 91 | ts_cell._fields_=[ | |
| 92 | ('idx', c_uint), | |
| 93 | ('vertex', POINTER(POINTER(ts_vertex))), | |
| 94 | ('nvertex', c_uint), | |
| 95 | ] | |
| 96 | ||
| 97 | class ts_cell_list(Structure): | |
| 98 | _fields_=[ | |
| 99 | ('ncmax', c_uint*3), | |
| 100 | ('cellno', c_uint), | |
| 101 | ('cell',POINTER(POINTER(ts_cell))), | |
| 102 | ('dcell', c_double), | |
| 103 | ('shift', c_double), | |
| 104 | ('max_occupancy', c_double), | |
| 105 | ('dmin_interspecies', c_double) | |
| 106 | ] | |
| 107 | ||
| 108 | class ts_spharm(Structure): | |
| 109 | _fields_=[ | |
| 110 | ('l',c_uint), | |
| 111 | ('ulm', POINTER(POINTER(c_double))), | |
| 112 | # ('ulmComplex', POINTER(POINTER(gsl_complex))), #poisci!!!! | |
| 113 | ('ulmComplex', POINTER(POINTER(c_double))), #temporary solution | |
| 114 | ('sumUlm2', POINTER(POINTER(c_double))), | |
| 115 | ('N', c_uint), | |
| 116 | ('co',POINTER(POINTER(c_double))), | |
| 117 | ('Ylmi', POINTER(POINTER(c_double))), | |
| 118 | ] | |
| 119 | ||
| 120 | ts_poly._fields_=[ | |
| 121 | ('vlist', POINTER(ts_vertex_list)), | |
| 122 | ('blist', POINTER(ts_bond_list)), | |
| 123 | ('grafted_vtx',POINTER(ts_vertex)), | |
| 124 | ('k', c_double), | |
| 125 | ] | |
| 126 | ||
| 127 | class ts_poly_list(Structure): | |
| 128 | _fields_=[('n',c_uint),('poly',POINTER(POINTER(ts_poly)))] | |
| 129 | ||
| 130 | class ts_tape(Structure): | |
| 131 | _fields_=[ | |
| 132 | ('nshell',c_long), | |
| 133 | ('ncxmax',c_long), | |
| 134 | ('ncymax',c_long), | |
| 135 | ('nczmax',c_long), | |
| 136 | ('npoly',c_long), | |
| 137 | ('nmono',c_long), | |
| 138 | ('internal_poly',c_long), | |
| 139 | ('nfil',c_long), | |
| 140 | ('nfono', c_long), | |
| 141 | ('R_nucleus',c_long), | |
| 142 | ('R_nucleusX',c_double), | |
| 143 | ('R_nucleusY',c_double), | |
| 144 | ('R_nucleusZ',c_double), | |
| 145 | ('pswitch',c_long), | |
| 146 | ('constvolswitch',c_long), | |
| 147 | ('constareaswitch',c_long), | |
| 148 | ('constvolprecision',c_double), | |
| 149 | ('multiprocessing',c_char_p), | |
| 150 | ('brezveze0',c_long), | |
| 151 | ('brezveze1',c_long), | |
| 152 | ('brezveze2',c_long), | |
| 153 | ('xk0',c_double), | |
| 154 | ('dmax',c_double), | |
| 155 | ('dmin_interspecies',c_double), | |
| 156 | ('stepsize',c_double), | |
| 157 | ('kspring',c_double), | |
| 158 | ('xi',c_double), | |
| 159 | ('pressure',c_double), | |
| 160 | ('iterations',c_long), | |
| 161 | ('inititer',c_long), | |
| 162 | ('mcsweeps',c_long), | |
| 163 | ('quiet',c_long), | |
| 164 | ('shc',c_long), | |
| 165 | ('number_of_vertice_with_c0',c_long), | |
| 166 | ('c0', c_double), | |
| 167 | ('w', c_double), | |
| 168 | ('F', c_double), | |
| 169 | ] | |
| 170 | ||
| 171 | ||
| 172 | class ts_vesicle(Structure): | |
| 173 | _fields_=[ | |
| 174 | ('vlist', POINTER(ts_vertex_list)), | |
| 175 | ('blist', POINTER(ts_bond_list)), | |
| 176 | ('tlist', POINTER(ts_triangle_list)), | |
| 177 | ('clist', POINTER(ts_cell_list)), | |
| 178 | ('nshell', c_uint), | |
| 179 | ('bending_rigidity',c_double), | |
| 180 | ('dmax',c_double), | |
| 181 | ('stepsize',c_double), | |
| 182 | ('cm', c_double*3), | |
| 183 | ('volume', c_double), | |
| 184 | ('sphHarmonics',POINTER(ts_spharm)), | |
| 185 | ('poly_list', POINTER(ts_poly_list)), | |
| 186 | ('filament_list', POINTER(ts_poly_list)), | |
| 187 | ('spring_constant', c_double), | |
| 188 | ('pressure', c_double), | |
| 189 | ('pswitch', c_int), | |
| 190 | ('tape', POINTER(ts_tape)), | |
| 191 | ('R_nucleus', c_double), | |
| 192 | ('R_nucleusX', c_double), | |
| 193 | ('R_nucleusY', c_double), | |
| 194 | ('R_nucleusZ', c_double), | |
| 195 | ('nucleus_center', c_double *3 ), | |
| 196 | ('area', c_double), | |
| 197 | ] | |
| 198 | ||
| 199 | ts_cluster._fields_=[('nvtx',c_uint),('idx',c_uint),('vtx', POINTER(POINTER(ts_vertex)))] | |
| 200 | ||
| 201 | class ts_cluster_list(Structure): | |
| a2f057 | 202 | _fields_=[('n',c_uint),('cluster',POINTER(POINTER(ts_cluster)))] |
| a4f8eb | 203 | |
| 83999e | 204 | |
| SP | 205 | |
| 206 | ||
| 207 | ts=CDLL('libtrisurf.so') | |
| a8e8b1 | 208 | |
| SP | 209 | |
| 210 | ||
| 211 | #function call wrappers | |
| 212 | def create_vesicle_from_tape(tape): | |
| 213 | """Using pointer for tape, it creates a vesicle, returning pointer to it.""" | |
| 214 | ts.create_vesicle_from_tape.argtype=POINTER(ts_tape) | |
| 215 | ts.create_vesicle_from_tape.restype=POINTER(ts_vesicle) | |
| 216 | return ts.create_vesicle_from_tape(tape) | |
| 217 | ||
| 218 | def parsetape(filename='tape'): | |
| 219 | """Loads tape with filename (if not given it defaults to 'tape'). It returns a pointer to structure for tape""" | |
| 220 | ts.parsetape.restype=POINTER(ts_tape) | |
| 221 | ts.parsetape.argtype=[c_char_p] | |
| 222 | return ts.parsetape(filename.encode('ascii')) | |
| 223 | ||
| 224 | def parseDump(filename): | |
| 225 | """Loads a vtu file with 'filename' and creates a vesicle returning pointer to it""" | |
| 226 | ts.parseDump.argtype=[c_char_p] | |
| 227 | ts.parseDump.restype=POINTER(ts_vesicle) | |
| 228 | vesicle=ts.parseDump(filename.encode('ascii')) | |
| 229 | return vesicle | |
| 230 | ||
| 231 | def single_timestep(vesicle): | |
| 232 | """Makes a single timestep in simulations. Returns a tuple of vmsrt and bfrt (vertex move success rate and bond flip success rate)""" | |
| 233 | ts.single_timestep.argtype=[POINTER(ts_vesicle),POINTER(c_double),POINTER(c_double)] | |
| 234 | vmsrt=c_double(0.0) | |
| 235 | bfsrt=c_double(0.0) | |
| 236 | ts.single_timestep(vesicle,byref(vmsrt),byref(bfsrt)) | |
| 237 | return (vmsrt.value, bfsrt.value) | |
| 238 | ||
| 239 | def write_vertex_xml_file(vesicle,timestep_no=0): | |
| 240 | """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""" | |
| 241 | ts.write_vertex_xml_file.argtypes=[POINTER(ts_vesicle),c_int] | |
| 242 | ts.write_vertex_xml_file(vesicle,c_int(timestep_no)) | |
| 243 | ||
| 244 | ||
| 245 | def vesicle_free(vesicle): | |
| 246 | """Free memory of the whole vesicle""" | |
| 247 | ts.vesicle_free.argtype=[POINTER(ts_vesicle)] | |
| 248 | ts.vesicle_free(vesicle) | |
| 249 | ||
| a2f057 | 250 | def vesicle_volume(vesicle): |
| SP | 251 | ts.vesicle_volume.argtype=[POINTER(ts_vesicle)] |
| 252 | ts.vesicle_volume(vesicle) | |
| a8e8b1 | 253 | |
| a2f057 | 254 | def vesicle_area(vesicle): |
| SP | 255 | ts.vesicle_area.argtype=[POINTER(ts_vesicle)] |
| 256 | ts.vesicle_area(vesicle) | |
| a8e8b1 | 257 | |
| a2f057 | 258 | def gyration_eigen(vesicle): |
| SP | 259 | ts.gyration_eigen.argtype=[POINTER(ts_vesicle), POINTER(c_double), POINTER(c_double), POINTER(c_double)] |
| 260 | l1=c_double(0.0) | |
| 261 | l2=c_double(0.0) | |
| 262 | l3=c_double(0.0) | |
| 263 | ts.gyration_eigen(vesicle , byref(l1), byref(l2), byref(l3)) | |
| 264 | return (l1.value, l2.value, l3.value) | |
| 265 | ||
| 266 | def vesicle_meancurvature(vesicle): | |
| 267 | ts.vesicle_meancurvature.argtype=[POINTER(ts_vesicle)] | |
| 268 | ts.vesicle_meancurvature.restype=c_double | |
| 269 | return ts.vesicle_meancurvature(vesicle) | |
| 270 | ||
| 271 | def init_cluster_list(): | |
| 272 | ts.init_cluster_list.restype=POINTER(ts_cluster_list) | |
| 273 | ret=ts.init_cluster_list() | |
| 274 | return ret | |
| 275 | ||
| 276 | def clusterize_vesicle(vesicle, cluster_list): | |
| 277 | ts.clusterize_vesicle.argtype=[POINTER(ts_vesicle), POINTER(ts_cluster_list)] | |
| 278 | ts.clusterize_vesicle(vesicle, cluster_list) | |
| 279 | ||
| 280 | def cluster_list_free(cluster_list): | |
| 281 | """Free memory of cluster list""" | |
| 282 | ts.cluster_list_free.argtype=[POINTER(ts_cluster_list)] | |
| 283 | ts.cluster_list_free(cluster_list) | |
| 284 | ||
| 285 | ||
| 286 | ||