def test_two_particles_cannot_be_in_same_positions(self):
        master = Master(100, 1)
        master.create_nanoparticles_and_ligands(2, 10, 10, 1)
        master.agents[0].position = np.array([1, 1, 1])
        position = np.array([1, 1, 1])

        self.assertFalse(master._check_space_available_nanoparticle(position))
    def test_correct_number_of_nanoparticles_are_created(self):
        master = Master(100, 1)
        master.create_nanoparticles_and_ligands(10, 1, 1, 1)
        self.assertEqual(10, master.number_of_nanoparticles)

        agents = [i for i in master.agents if isinstance(i, Nanoparticle)]
        self.assertEqual(10, len(agents))
 def test_no_nanoparticles_are_touching(self):
     master = Master(1000, 1)
     master.create_nanoparticles_and_ligands(100, 10, 10, 1)
     positions = [i.position for i in master.agents]
     combs = combinations(positions, 2)
     distance = [np.linalg.norm(a - b) for (a, b) in combs]
     self.assertTrue(all([i > 22 for i in distance]))
    def test_two_particles_can_be_far_away(self):
        master = Master(100, 1)
        master.create_nanoparticles_and_ligands(2, 10, 10, 1)
        master.agents[0].position = np.array([1, 1, 1])
        position = np.array([50, 50, 50])

        self.assertTrue(master._check_space_available_nanoparticle(position))
 def test_all_receptors_have_correct_length(self):
     master = Master(100, 1)
     master.create_nanoparticles_and_ligands(10, 1, 1, 1)
     master.create_receptors(10, 1)
     [
         self.assertEqual(1, a.receptor_length) for a in master.agents
         if isinstance(a, Receptor)
     ]
 def test_correct_number_ligands_are_created(self):
     master = Master(100, 1)
     master.create_nanoparticles_and_ligands(100, 10, 1, 1)
     self.assertEqual(master.ligand_length, 1)
     self.assertEqual(master.number_of_ligands, 10)
     ligands = [i.ligands for i in master.agents]
     for l in ligands:
         self.assertEqual(10, len(l))
 def test_no_nanoparticles_outside_area(self):
     master = Master(1000, 1)
     master.create_nanoparticles_and_ligands(100, 10, 10, 1)
     positions = [i.position for i in master.agents]
     self.assertTrue(
         all([(i[0] < 1000 and i[1] < 1000 and i[2] < 1000)
              for i in positions]))
     self.assertTrue(
         all([(i[0] > 0 and i[1] > 0 and i[2] > 0) for i in positions]))
 def test_two_particles_can_be_really_close_without_touching(self):
     master = Master(100, 1)
     master.create_nanoparticles_and_ligands(2, 10, 10, 1)
     master.agents[0].position = np.array([1, 1, 1])
     position = np.array([23, 1, 1])
     self.assertTrue(master._check_space_available_nanoparticle(position))
     x = 22 / np.sqrt(3) + 1
     position = np.array([x, x, x])
     self.assertTrue(master._check_space_available_nanoparticle(position))
 def test_two_particles_cannot_be_touching(self):
     master = Master(100, 1)
     master.create_nanoparticles_and_ligands(2, 10, 10, 1)
     master.agents[0].position = np.array([1, 1, 1])
     position = np.array([23 - 1e-10, 1, 1])
     self.assertFalse(master._check_space_available_nanoparticle(position))
     x = 22 / np.sqrt(3) + 1 - 1e-10
     position = np.array([x, x, x])
     self.assertFalse(master._check_space_available_nanoparticle(position))
示例#10
0
def binding_energy():
    print('Binding Energy -------------')
    d = np.linspace(5, 25, 5).tolist()
    data = {}
    means = []
    errors = []
    time_data = []
    for i in d:
        variable_finals = []
        for _ in range(3):
            number_of_seconds = 1  # i.e. 1 hour = 3600 seconds
            model = Master(dimension=1000,
                           binding_energy=int(i),
                           time_unit=10e-3,
                           number_of_receptors=2,
                           receptor_length=100,
                           number_of_nanoparticles=1,
                           nanoparticle_radius=50,
                           number_of_ligands=2,
                           ligand_length=7,
                           binding_distance=4,
                           receptor_radius=3,
                           ligand_radius=3,
                           cell_diffusion_coef=1)
            model.create_receptors()  # 100 nm for receptor
            model.create_nanoparticles_and_ligands(
            )  # 1-2 nm for ligand  # 95 particles
            print(
                f'{model.dimension/1000} μm\u00b3 system, {model.binding_energy} binding energy, {model.number_of_nanoparticles} Nanoparticles,\n'
                f'{model.nanoparticle_radius} nm Nanoparticle Radius, {model.number_of_ligands} Ligands, Ligand length {model.ligand_length} nm,\n'
                f'{model.number_of_receptors} Receptors, {model.receptor_length} nm Receptor length, {model.binding_distance} Binding distance'
            )
            model.run(steps=number_of_seconds)  # 3600 for 1 hour
            print(f'The surface coverage is {model.surface_coverage}')
            variable_finals.append(model.surface_coverage)
            time_data.append(np.array(model.coverage))
        mean_time = np.mean(time_data, axis=0)
        error_time = np.std(time_data, axis=0)
        data[f'{model.binding_energy} KT binding energy '] = np.array(
            [list(range(0, model.time + 1)), mean_time, error_time])
        mean_coverage = np.mean(np.array(variable_finals))
        print(f'The mean surface coverage is {mean_coverage}')
        errors.append(np.std(np.array(variable_finals)))
        means.append(np.mean(np.array(variable_finals)))
    plt.xlabel('Time (milliseconds)')
    plt.ylabel('Surface Coverage')
    for key, value in data.items():
        plt.plot(value[0], value[1], label=key)
        plt.fill_between(value[0],
                         value[1] - value[2],
                         value[1] + value[2],
                         alpha=0.2)
    plt.legend()
    plt.show()
    second_variable_plot('Binding energy (kt)', 'Surface Coverage', d, means,
                         errors)
 def test_no_receptor_tips_are_touching(self):
     for _ in range(100):
         master = Master(100, 1)
         master.create_nanoparticles_and_ligands(10, 1, 1, 1)
         master.create_receptors(100, 1)
         positions = [
             a.tip_position for a in master.agents
             if isinstance(a, Receptor)
         ]
         combs = combinations(positions, 2)
         distance = [np.linalg.norm(a - b) for (a, b) in combs]
         [self.assertNotAlmostEqual(d, 0) for d in distance]
 def test_no_receptor_bases_outside_area(self):
     for _ in range(100):
         master = Master(500, 1)
         master.create_nanoparticles_and_ligands(100, 10, 10, 1)
         positions = [
             i.base_position for i in master.agents
             if isinstance(i, Receptor)
         ]
         self.assertTrue(
             all([(i[0] < 1000 and i[1] < 1000 and i[2] < 1000)
                  for i in positions]))
         self.assertTrue(
             all([(i[0] > 0 and i[1] > 0 and i[2] > 0) for i in positions]))