示例#1
0
    def test_kmc_algorithm(self):
        np.random.seed(
            0
        )  # set random seed in order for the examples to reproduce the exact references

        transitions = [
            Transition(
                s1,
                gs,
                tdm=[0.5, 0.2],  # a.u.
                reorganization_energy=0.08,  # eV
                symmetric=True)
        ]

        vibrational_model = MarcusModel(transitions=transitions,
                                        temperature=300)  # Kelvin

        # list of transfer functions by state
        self.system.process_scheme = [
            GoldenRule(initial_states=(s1, gs),
                       final_states=(gs, s1),
                       electronic_coupling_function=forster_coupling_extended,
                       description='Forster',
                       arguments={
                           'ref_index': 2,
                           'longitude': 2,
                           'n_divisions': 30,
                           'transitions': transitions
                       },
                       vibrations=vibrational_model),
            DecayRate(initial_state=s1,
                      final_state=gs,
                      decay_rate_function=einstein_radiative_decay,
                      arguments={'transitions': transitions},
                      description='singlet_radiative_decay')
        ]

        self.system.cutoff_radius = 10.0  # interaction cutoff radius in Angstrom

        # some system analyze functions
        system_test_info(self.system)

        trajectories = calculate_kmc(
            self.system,
            num_trajectories=10,  # number of trajectories that will be simulated
            max_steps=100,  # maximum number of steps for trajectory allowed
            silent=True)

        # Results analysis
        analysis = TrajectoryAnalysis(trajectories)

        print('diffusion coefficient: {:9.5f} Angs^2/ns'.format(
            analysis.diffusion_coefficient('s1')))
        print('lifetime:              {:9.5f} ns'.format(
            analysis.lifetime('s1')))
        print('diffusion length:      {:9.5f} Angs'.format(
            analysis.diffusion_length('s1')))
        print('diffusion tensor (Angs^2/ns)')
        print(analysis.diffusion_coeff_tensor('s1'))

        print('diffusion length square tensor (Angs)')
        print(analysis.diffusion_length_square_tensor('s1'))

        test = {
            'diffusion coefficient':
            np.around(analysis.diffusion_coefficient('s1'), decimals=4),
            'lifetime':
            np.around(analysis.lifetime('s1'), decimals=4),
            'diffusion length':
            np.around(analysis.diffusion_length('s1'), decimals=4),
            'diffusion tensor':
            np.around(analysis.diffusion_coeff_tensor('s1',
                                                      unit_cell=[[0.0, 0.5],
                                                                 [0.2, 0.0]]),
                      decimals=4).tolist(),
            'diffusion length tensor':
            np.around(analysis.diffusion_length_square_tensor(
                's1', unit_cell=[[0.0, 0.5], [0.2, 0.0]]),
                      decimals=6).tolist()
        }
        print(test)

        ref = {
            'diffusion coefficient': 1586.4162,
            'lifetime': 0.3621,
            'diffusion length': 47.9375,
            'diffusion tensor': [[2048.6421, 3.4329], [3.4329, 1124.1904]],
            'diffusion length tensor': [[3142.8, 42.0], [42.0, 1453.2]]
        }

        self.assertDictEqual(ref, test)
示例#2
0
    def test_kmc_algorithm(self):
        np.random.seed(
            0
        )  # set random seed in order for the examples to reproduce the exact references

        # set additional system parameters
        self.system.process_scheme = [
            DirectRate(initial_states=(s1, gs),
                       final_states=(gs, s1),
                       rate_constant_function=transfer_rate,
                       arguments={'custom_constant': 1},
                       description='transport s1'),
            DirectRate(initial_states=(s1, s1),
                       final_states=(tt, ),
                       rate_constant_function=transfer_rate,
                       arguments={'custom_constant': 1},
                       description='merge s1-s1 -> tt'),
            DirectRate(initial_states=(tt, ),
                       final_states=(gs, gs),
                       rate_constant_function=decay_rate,
                       description='decay tt'),
            DirectRate(initial_states=(tt, gs),
                       final_states=(gs, tt),
                       rate_constant_function=decay_rate,
                       description='transport tt')
        ]

        self.system.cutoff_radius = 10.0  # interaction cutoff radius in Angstrom

        p = DirectRate(initial_states=(s1, s1),
                       final_states=(tt, ),
                       rate_constant_function=transfer_rate,
                       arguments={'custom_constant': 1},
                       description='custom2')
        #print(p.get_transition_connections())
        #exit()

        # some system analyze functions
        system_test_info(self.system)

        trajectories = calculate_kmc(
            self.system,
            num_trajectories=10,  # number of trajectories that will be simulated
            max_steps=50,  # maximum number of steps for trajectory allowed
            silent=True)

        # Results analysis
        analysis = TrajectoryAnalysis(trajectories)

        print('diffusion coefficient: {:9.5f} Angs^2/ns'.format(
            analysis.diffusion_coefficient('tt')))
        print('lifetime:              {:9.5f} ns'.format(
            analysis.lifetime('tt')))
        print('diffusion length:      {:9.5f} Angs'.format(
            analysis.diffusion_length('tt')))
        print('diffusion tensor (Angs^2/ns)')
        print(analysis.diffusion_coeff_tensor('tt'))

        print('diffusion length square tensor (Angs)')
        print(analysis.diffusion_length_square_tensor('tt'))

        test = {
            'diffusion coefficient':
            np.around(analysis.diffusion_coefficient('tt'), decimals=4),
            'lifetime':
            np.around(analysis.lifetime('tt'), decimals=4),
            'diffusion length':
            np.around(analysis.diffusion_length('tt'), decimals=4),
            'diffusion tensor':
            np.around(analysis.diffusion_coeff_tensor('tt'),
                      decimals=4).tolist(),
            'diffusion length tensor':
            np.around(np.sqrt(analysis.diffusion_length_square_tensor('tt')),
                      decimals=4).tolist()
        }

        ref = {
            'diffusion coefficient': 0.4819,
            'lifetime': 28.3726,
            'diffusion length': 4.1018,
            'diffusion tensor': [[0.4819]],
            'diffusion length tensor': [[4.1018]]
        }

        self.assertDictEqual(ref, test)
示例#3
0
    def test_kmc_algorithm(self):
        np.random.seed(0)  # set random seed in order for the examples to reproduce the exact references

        transitions = [Transition(s1, gs,
                                  tdm=[0.3, 0.1],  # a.u.
                                  reorganization_energy=0.08,  # eV
                                  symmetric=True)]

        marcus = MarcusModel(transitions=transitions,
                             temperature=300)  # Kelvin

        # list of transfer functions by state
        self.system.process_scheme = [GoldenRule(initial_states=(s1, gs), final_states=(gs, s1),
                                                 electronic_coupling_function=forster_coupling_extended,
                                                 description='Forster',
                                                 arguments={'ref_index': 2, 'longitude': 2, 'n_divisions': 30,
                                                            'transitions': transitions},
                                                 vibrations=marcus
                                                 ),
                                      DecayRate(initial_state=s1, final_state=gs,
                                                decay_rate_function=einstein_radiative_decay,
                                                arguments={'transitions': transitions},
                                                description='singlet_radiative_decay')
                                      ]

        self.system.cutoff_radius = 10.0  # interaction cutoff radius in Angstrom

        # some system analyze functions
        system_test_info(self.system)

        trajectories = calculate_kmc(self.system,
                                     num_trajectories=10,  # number of trajectories that will be simulated
                                     max_steps=100,  # maximum number of steps for trajectory allowed
                                     silent=True)

        # Results analysis
        analysis = TrajectoryAnalysis(trajectories)

        print('diffusion coefficient: {:9.5f} Angs^2/ns'.format(analysis.diffusion_coefficient('s1')))
        print('lifetime:              {:9.5f} ns'.format(analysis.lifetime('s1')))
        print('diffusion length:      {:9.5f} Angs'.format(analysis.diffusion_length('s1')))
        print('diffusion tensor (Angs^2/ns)')
        print(analysis.diffusion_coeff_tensor('s1'))

        print('diffusion length square tensor (Angs)')
        print(analysis.diffusion_length_square_tensor('s1'))

        test = {'diffusion coefficient': np.around(analysis.diffusion_coefficient('s1'), decimals=4),
                'lifetime': np.around(analysis.lifetime('s1'), decimals=4),
                'diffusion length': np.around(analysis.diffusion_length('s1'), decimals=4),
                'diffusion tensor': np.around(analysis.diffusion_coeff_tensor('s1', unit_cell=[[5.0, 1.0],
                                                                                               [1.0, 5.0]]), decimals=4).tolist(),
                'diffusion length tensor': np.around(analysis.diffusion_length_square_tensor('s1', unit_cell=[[5.0, 1.0],
                                                                                                              [1.0, 5.0]]), decimals=4).tolist()
                }

        ref = {'diffusion coefficient': 120.7623,
               'lifetime': 2.1215,
               'diffusion length': 33.0968,
               'diffusion tensor': [[198.6035, -72.076],
                                    [-72.076, 98.3641]],
               'diffusion length tensor': [[1606.8, -728.0],
                                           [-728.0, 1144.0]]
               }


        self.maxDiff = None
        __import__('sys').modules['unittest.util']._MAX_LENGTH = 999999999
        self.assertDictEqual(ref, test)
示例#4
0
    def test_kmc_algorithm(self):
        np.random.seed(
            0
        )  # set random seed in order for the examples to reproduce the exact references

        transitions = [Transition(s1, gs, symmetric=True)]

        # list of transfer functions by state
        self.system.process_scheme = [
            SimpleRate(initial_states=(s1, gs),
                       final_states=(gs, s1),
                       rate_constant=0.1),
            SimpleRate(initial_states=(s1, ),
                       final_states=(gs, ),
                       rate_constant=0.01)
        ]

        # some system analyze functions
        system_test_info(self.system)

        trajectories = calculate_kmc(
            self.system,
            num_trajectories=
            500,  # number of trajectories that will be simulated
            max_steps=1000,  # maximum number of steps for trajectory allowed
            silent=True)

        # Results analysis
        analysis = TrajectoryAnalysis(trajectories)

        print('diffusion coefficient: {:9.5f} Angs^2/ns'.format(
            analysis.diffusion_coefficient('s1')))
        print('lifetime:              {:9.5f} ns'.format(
            analysis.lifetime('s1')))
        print('diffusion length:      {:9.5f} Angs'.format(
            analysis.diffusion_length('s1')))
        print('diffusion tensor (Angs^2/ns)')
        print(analysis.diffusion_coeff_tensor('s1'))

        print('diffusion length square tensor (Angs)')
        print(analysis.diffusion_length_square_tensor('s1'))

        test = {
            'diffusion coefficient':
            np.around(analysis.diffusion_coefficient('s1'), decimals=4),
            'lifetime':
            np.around(analysis.lifetime('s1'), decimals=4),
            'diffusion length':
            np.around(analysis.diffusion_length('s1'), decimals=4),
            'diffusion tensor':
            np.around(analysis.diffusion_coeff_tensor('s1',
                                                      unit_cell=[[0.0, 0.5],
                                                                 [0.2, 0.0]]),
                      decimals=4).tolist(),
            'diffusion length tensor':
            np.around(analysis.diffusion_length_square_tensor(
                's1', unit_cell=[[0.0, 0.5], [0.2, 0.0]]),
                      decimals=6).tolist()
        }
        print(test)

        ref = {
            'diffusion coefficient': 2.4439,
            'lifetime': 92.7496,
            'diffusion length': 30.1679,
            'diffusion tensor': [[2.1338, 0.1308], [0.1308, 2.7539]],
            'diffusion length tensor': [[798.7, 25.7], [25.7, 1021.5]]
        }

        # This is just for visual comparison (not accounted in the test)
        decay = 0.01
        transfer = 0.1
        distance = 5

        print('analytical model')
        print('----------------')
        data = get_analytical_model(distance, analysis.n_dim, transfer, decay)
        print('results analytical:', data)

        self.assertDictEqual(ref, test)
示例#5
0
                         #           rate_constant=1,
                         #           description='singlet-singlet annihilation'),
                         #SimpleRate(initial_states=(t1, s1), final_states=(gs, gs),
                         #           rate_constant=100,
                         #           description='singlet-triplet annihilation'),
                         ]

np.random.seed(0)

system.add_excitation_random(s1, 2)
system_test_info(system)
visualize_system(system)

# exit()
trajectories = calculate_kmc(system,
                             num_trajectories=50,    # number of trajectories that will be simulated
                             max_steps=1000,         # maximum number of steps for trajectory allowed
                             silent=False)


store_trajectory_list(trajectories, 'singlet_fission.h5')
#trajectories = load_trajectory_list('singlet_fission.h5')

analysis = TrajectoryAnalysis(trajectories)

for s in ['s1', 't1']:
    print('STATE: ', s)
    print('diffusion coefficient (average): {} angs^2/ns'.format(analysis.diffusion_coefficient(s)))
    print('lifetime: {} ns'.format(analysis.lifetime(s)))
    print('diffusion length: {} angs'.format(analysis.diffusion_length(s)))

    print('diffusion tensor')
示例#6
0
    def test_kmc_algorithm(self):
        np.random.seed(
            0
        )  # set random seed in order for the examples to reproduce the exact references

        # set additional system parameters
        self.system.process_scheme = [
            DirectRate(initial_states=(s1, gs),
                       final_states=(gs, s1),
                       rate_constant_function=transfer_rate,
                       arguments={'custom_constant': 1},
                       description='transport'),
            DirectRate(initial_states=(s1, ),
                       final_states=(gs, ),
                       rate_constant_function=decay_rate,
                       description='custom decay rate'),
            DirectRate(initial_states=(s2, s2),
                       final_states=(gs, s1),
                       rate_constant_function=decay_rate,
                       description='merge'),
            DirectRate(initial_states=(s1, gs),
                       final_states=(s2, s2),
                       rate_constant_function=decay_rate,
                       description='split'),
            DirectRate(initial_states=(s2, gs),
                       final_states=(gs, s2),
                       rate_constant_function=transfer_rate,
                       arguments={'custom_constant': 1},
                       description='transport 2'),
            DirectRate(initial_states=(s2, ),
                       final_states=(gs, ),
                       rate_constant_function=decay_rate,
                       description='custom decay rate 2'),
        ]

        #print([s.label for s in self.system.decay_scheme[0].initial], '--',
        #      [s.label for s in self.system.decay_scheme[0].final])
        #print([s.label for s in self.system.decay_scheme[1].initial], '--',
        #      [s.label for s in self.system.decay_scheme[1].final])

        self.system.cutoff_radius = 10.0  # interaction cutoff radius in Angstrom

        # some system analyze functions
        system_test_info(self.system)

        trajectories = calculate_kmc(
            self.system,
            num_trajectories=50,  # number of trajectories that will be simulated
            max_steps=18,  # maximum number of steps for trajectory allowed
            silent=True)

        # Results analysis
        analysis = TrajectoryAnalysis(trajectories)

        for traj in trajectories:
            print('diff:', traj.get_diffusion('s1'))
            print('diff none:', traj.get_diffusion(None))
            #print('path:', traj._trajectory_node_path())
            #print('path:', trajectories[0]._trajectory_node_path_new())

        #print('-> diff:', trajectories[8].get_diffusion('s1'))
        #print('-> diff none:', trajectories[8].get_diffusion(None))
        #print('path:', trajectories[8]._trajectory_node_path())

        #trajectories[0].plot_graph().show()

        #exit()

        print('diffusion coefficient: {:9.5f} Angs^2/ns'.format(
            analysis.diffusion_coefficient('s1')))
        print('lifetime:              {:9.5f} ns'.format(
            analysis.lifetime('s1')))
        print('diffusion length:      {:9.5f} Angs'.format(
            analysis.diffusion_length('s1')))
        print('diffusion tensor (Angs^2/ns)')
        print(analysis.diffusion_coeff_tensor('s1'))

        print('diffusion length square tensor (Angs)')
        print(analysis.diffusion_length_square_tensor('s1'))

        test = {
            'diffusion coefficient':
            np.around(analysis.diffusion_coefficient('s1'), decimals=4),
            'lifetime':
            np.around(analysis.lifetime('s1'), decimals=4),
            'diffusion length':
            np.around(analysis.diffusion_length('s1'), decimals=4),
            'diffusion tensor':
            np.around(analysis.diffusion_coeff_tensor('s1'),
                      decimals=4).tolist(),
            'diffusion length tensor':
            np.around(np.sqrt(analysis.diffusion_length_square_tensor('s1')),
                      decimals=4).tolist()
        }

        print(test)

        ref = {
            'diffusion coefficient': 3.5571,
            'lifetime': 2.2493,
            'diffusion length': 3.9478,
            'diffusion tensor': [[3.5571]],
            'diffusion length tensor': [[3.9478]]
        }

        self.assertDictEqual(ref, test)
示例#7
0
    def test_kmc_algorithm_2(self):
        np.random.seed(
            0
        )  # set random seed in order for the examples to reproduce the exact references

        transitions = [
            Transition(s1,
                       gs,
                       tdm=[0.01],
                       reorganization_energy=0.07,
                       symmetric=True)
        ]

        # set additional system parameters
        self.system.process_scheme = [
            GoldenRule(initial_states=(s1, gs),
                       final_states=(gs, s1),
                       electronic_coupling_function=forster_coupling,
                       description='Forster coupling',
                       arguments={
                           'ref_index': 1,
                           'transitions': transitions
                       },
                       vibrations=MarcusModel(transitions=transitions)),
            DecayRate(initial_state=s1,
                      final_state=gs,
                      decay_rate_function=decay_rate,
                      description='custom decay rate')
        ]

        self.system.cutoff_radius = 10.0  # interaction cutoff radius in Angstrom

        # some system analyze functions
        system_test_info(self.system)

        trajectories = calculate_kmc(
            self.system,
            num_trajectories=10,  # number of trajectories that will be simulated
            max_steps=10000,  # maximum number of steps for trajectory allowed
            silent=True)

        # Results analysis
        analysis = TrajectoryAnalysis(trajectories)

        print('diffusion coefficient: {:9.5f} Angs^2/ns'.format(
            analysis.diffusion_coefficient('s1')))
        print('lifetime:              {:9.5f} ns'.format(
            analysis.lifetime('s1')))
        print('diffusion length:      {:9.5f} Angs'.format(
            analysis.diffusion_length('s1')))
        print('diffusion tensor (Angs^2/ns)')
        print(analysis.diffusion_coeff_tensor('s1'))

        print('diffusion length square tensor (Angs)')
        print(analysis.diffusion_length_square_tensor('s1'))

        test = {
            'diffusion coefficient':
            np.around(analysis.diffusion_coefficient('s1'), decimals=4),
            'lifetime':
            np.around(analysis.lifetime('s1'), decimals=4),
            'diffusion length':
            np.around(analysis.diffusion_length('s1'), decimals=4),
            'diffusion tensor':
            np.around(analysis.diffusion_coeff_tensor('s1'),
                      decimals=4).tolist(),
            'diffusion length tensor':
            np.around(np.sqrt(analysis.diffusion_length_square_tensor('s1')),
                      decimals=6).tolist()
        }

        print(test)
        ref = {
            'diffusion coefficient': 0.4265,
            'lifetime': 24.1692,
            'diffusion length': 5.4498,
            'diffusion tensor': [[0.4265]],
            'diffusion length tensor': [[5.449771]]
        }

        self.assertDictEqual(ref, test)