Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. #!/usr/bin/env python3.4
  2. """
  3. Calculate titration volumes from concentrate.
  4.  
  5. Pariksheet Nanda <omsai@member.fsf.org> 2015
  6.  
  7. License: Public Domain
  8.  
  9. """
  10.  
  11. from argparse import ArgumentParser
  12.  
  13. if __name__ == '__main__':
  14. parser = ArgumentParser(
  15. #'titer',
  16. description='Calculate titration volumes from concentrate.'
  17. )
  18. parser.add_argument(
  19. 'concentrate_density',
  20. type=float,
  21. help='original solution density (in 10^4 cells / ml).'
  22. )
  23. parser.add_argument(
  24. '-t',
  25. '--diluted-density',
  26. type=float,
  27. default=10.0,
  28. help='required solution density (default: 10x10^4 cells/ml).'
  29. )
  30. parser.add_argument(
  31. '-v',
  32. '--media-volume',
  33. type=float,
  34. default=10.0,
  35. help='final volume of media only (default: 10 ml).'
  36. )
  37. args = parser.parse_args()
  38.  
  39. if args.concentrate_density < args.diluted_density:
  40. raise ValueError("Stock solution density {0} cannot be less than diluted {1}.".format(args.concentrate_density, args.diluted_density))
  41.  
  42. concentrate_sub_volume = (
  43. args.diluted_density * args.media_volume
  44. / (args.concentrate_density - args.diluted_density)
  45. )
  46. """
  47. We derive the above equation as follows:
  48. c1 * v1 = c2 * v2
  49.  
  50. Where 1 = concentrate solution and 2 = diluted solution.
  51. We need to solve for v1:
  52.  
  53. c1 * v1 = c2 * (v_media + v1)
  54. c1 * v1 = c2 * v_media + c2 * v1
  55. c1 * v1 - c2 * v1 = c2 * v_media
  56. v1 * (c1 - c2) = c2 * v_media
  57. v1 = c2 * v_media / (c1 - c2)
  58.  
  59. """
  60.  
  61. print('Add {0} ul of stock to {1} ml of media, to get a dilution of {2} x 10^4 cells/ml using a concentrate density of {3} x 10^4 cells/ml'.format(
  62. int(concentrate_sub_volume * 1000),
  63. args.media_volume,
  64. args.diluted_density,
  65. args.concentrate_density,
  66. ))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement