Advertisement
Guest User

Eindopdracht_cotransporter

a guest
Jan 21st, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.00 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. """template for creating a functioning cotransporter sim. script"""
  3.  
  4. __author__ = ""
  5.  
  6. #imports
  7. import sys
  8. from pypovray import pypovray, SETTINGS, pdb, logger
  9. from vapory import Sphere, Scene, Pigment, Cylinder, Camera, Texture, Finish, Blob, LightSource
  10.  
  11. #constants
  12. GLUT1_model = Texture(Pigment('color', [0, 1, 1], 'filter', 0),
  13.                            Finish('phong', 0, 'reflection', 0))
  14. phosphorkop_model = Texture(Pigment('color', [1, 0, 0], 'filter', 0),
  15.                            Finish('phong', 0, 'reflection', 0))
  16. phosphorsta_model = Texture(Pigment('color', [1, 0, 0], 'filter', 0),
  17.                            Finish('phong', 0, 'reflection', 0))
  18. Na_model = Texture(Pigment('color', [0, 1, 0], 'filter', 0),
  19.                            Finish('phong', 0, 'reflection', 0))
  20.  
  21.  
  22. camera = Camera('location', [-2, 8, 45], 'look_at', [0, 5, 0])
  23. light        = LightSource([0, 0, 30], 0.8)
  24. Aant_lip = 20
  25. Begin_lip = -10
  26.  
  27.  
  28. #functions
  29. def objects():
  30.     #create the blob, ions and glucose
  31.  
  32.     global  Further_protein, phosphorkopbin, phosphorkopbuit, phosphorstabin, phosphorstabuit
  33.  
  34.     Further_protein = Sphere([2.5, 3.5, -3], 3, 'scale', [5, 1.5, 1.5], GLUT1_model)
  35.     phosphorkopbuit = Sphere([0, 0, 0], 2.5, 1.75,phosphorkop_model)
  36.     phosphorstabuit = Cylinder([0, 0, 0], [6.5, 0, 0], 1.25, 1,phosphorsta_model)
  37.     phosphorkopbin = Sphere([6.5, 0, 0], 2.5, 1.75,phosphorkop_model)
  38.     phosphorstabin = Cylinder([6.5, 0, 0], [0, 0, 0], 1.25, 1,phosphorsta_model)
  39.  
  40.  
  41. def membrane_outside():
  42.     #Creates the outside membrane
  43.     phosbuit = []
  44.  
  45.     for i in range(Aant_lip):
  46.         y_coord = (Begin_lip + i) * 3.5
  47.         if y_coord > 1 and y_coord < 8:
  48.             pass
  49.         else:
  50.             phosbuit.append(Blob('threshold', .45, phosphorkopbuit, phosphorstabuit, 'translate', [6, y_coord, 0]))
  51.     return phosbuit
  52.  
  53.  
  54. def membrane_inside():
  55.     #Creates the inner membrane
  56.     phosbin = []
  57.  
  58.     for i in range(Aant_lip):
  59.         y_coord = ((Begin_lip + 3.5) + i) * 3.5
  60.         if y_coord > 1 and y_coord < 9:
  61.             pass
  62.         else:
  63.             phosbin.append(Blob('threshold', .45, phosphorkopbin, phosphorstabin, 'translate', [12, y_coord, 0]))
  64.     return phosbin
  65.  
  66.  
  67. def gate_up(step, nframes):
  68.     #Move the protein up
  69.     start_step = 60
  70.     end_step = 70
  71.     y_coord = 0
  72.  
  73.  
  74.  
  75.     if step < end_step:
  76.         if start_step < step < end_step:
  77.             #This if function opens the gate
  78.             y_start = 7
  79.             y_end = 8
  80.         elif step <= start_step:
  81.             y_start = 7
  82.             y_end = 7
  83.  
  84.         y_total = y_end - y_start
  85.  
  86.         total_distance_per_frame = y_total / nframes
  87.  
  88.         y_coord = y_start + (step * total_distance_per_frame)
  89.  
  90.  
  91.  
  92.     elif step >= end_step:
  93.         y_coord = 8
  94.  
  95.  
  96.     Upper_protein = Sphere([2.5, y_coord, 0], 3, 'scale', [5, 1.5, 1.5], GLUT1_model)
  97.  
  98.     return Upper_protein
  99.  
  100.  
  101. def gate_down(step, nframes):
  102.     # Move the protein down
  103.     start_step = 60
  104.     end_step = 70
  105.     y_coord = 0
  106.  
  107.  
  108.     if step < end_step:
  109.         if start_step < step < end_step:
  110.             y_start = 0
  111.             y_end = -1
  112.         elif step <= start_step:
  113.             y_start = 0
  114.             y_end = 0
  115.  
  116.  
  117.         y_total = y_end - y_start
  118.  
  119.         total_distance_per_frame = y_total / nframes
  120.  
  121.         y_coord = y_start + (step * total_distance_per_frame)
  122.  
  123.     elif step >= end_step:
  124.         y_coord = -1
  125.  
  126.  
  127.     Lower_protein = Sphere([2.5, y_coord, 0], 3, 'scale', [5, 1.5, 1.5], GLUT1_model)
  128.  
  129.     return Lower_protein
  130.  
  131.  
  132. def glu_move(step, nframes):
  133.     #move the glucose through the blob
  134.     start_step = 60
  135.     use_step = step - start_step
  136.  
  137.     if step > start_step:
  138.         x_start = -12
  139.         x_end = 0
  140.     else:
  141.         x_start = -12
  142.         x_end = -12
  143.  
  144.     x_total = x_end - x_start
  145.  
  146.     total_distance_per_frame = x_total / (.18 *nframes)
  147.  
  148.     x_coord = x_start + (use_step * total_distance_per_frame)
  149.  
  150.  
  151.     GLUCOSE = pdb.PDBMolecule('{}/pdb/glucose-2.pdb'.format(SETTINGS.AppLocation), center=True, offset=[-12, 3.75, 0])
  152.  
  153.     GLUCOSE.move_to([x_coord, 3.75, 0])
  154.  
  155.     return GLUCOSE
  156.  
  157.  
  158. def ion_move(step, nframes):
  159.     #move the ions through the blob
  160.  
  161.     if step > 20:
  162.         x_start = -12
  163.         x_end = 0
  164.     else:
  165.         x_start = -12
  166.         x_end = -12
  167.  
  168.     x_total = x_end - x_start
  169.  
  170.     total_distance_per_frame = x_total / (.25 * nframes)
  171.  
  172.     x_coord = x_start + step * total_distance_per_frame
  173.  
  174.     Na_ion = Sphere([x_coord, 9.5, 0], 2.04, Na_model)
  175.  
  176.     return Na_ion
  177.  
  178.  
  179. def transparant(step):
  180.     #make the blob transparant as soon as the glucose and ions go in
  181.     filter_col = 0
  182.     Nearest_Protein = []
  183.  
  184.     if step > 20:
  185.         filter_col += 0.1 * (step/5)
  186.         if filter_col >= .8:
  187.             filter_col = .8
  188.  
  189.  
  190.     Nearest_protein = Sphere([2.5, 3.5, 3], 3, 'scale', [5, 1.5, 1.5],
  191.                     Texture(Pigment('color', [0, 1, 1], 'filter', filter_col),
  192.                     Finish('phong', 0, 'reflection', 0)))
  193.  
  194.     Nearest_Protein.append(Nearest_protein)
  195.     return Nearest_Protein
  196.  
  197.  
  198. def frame(step):
  199.     #here goes all scene thingy's
  200.     logger.info(" @Step: %s", step)
  201.     # Getting the total number of frames, see the configuration file
  202.     nframes = eval(SETTINGS.NumberFrames)
  203.  
  204.     phosbuit = membrane_outside()
  205.     phosbin = membrane_inside()
  206.  
  207.     GLUCOSE = glu_move(step, nframes)
  208.     Nearest_Protein = transparant(step)
  209.     Na_ion = ion_move(step, nframes)
  210.     Upper_protein = gate_up(step, nframes)
  211.     Lower_protein = gate_down(step, nframes)
  212.  
  213.  
  214.  
  215.     return Scene(camera,
  216.                  objects=[light,  Further_protein, Upper_protein, Lower_protein, Na_ion] + GLUCOSE.povray_molecule + phosbuit + phosbin + Nearest_Protein)
  217.  
  218.  
  219. #main
  220. def main(args):
  221.     #prep
  222.     objects()
  223.  
  224.  
  225.     #work
  226.     pypovray.render_scene_to_mp4(frame)
  227.     #pypovray.render_scene_to_png(frame, 1)
  228.  
  229.     #finalize
  230.     return 0
  231.  
  232.  
  233. if __name__ == '__main__':
  234.     exitcode = main(sys.argv)
  235.     sys.exit(exitcode)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement