Пример #1
0
    def test_raises_error_when_direction_not_found(self):
        path = "./files/water_on_graphene"

        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True)

        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )

        with pytest.raises(analysis.KeyNotFound):
            simulation.compute_density_profile(["O", "H"], direction="w")
    def test_returns_profile_radial_direction_parallel_to_z_axis(self):

        path = "./files/water_in_carbon_nanotube/m12_n12/classical"

        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True)
        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )
        simulation.compute_density_profile(["O", "H"], direction="radial z")

        assert simulation.density_profiles.get("O H - radial z")
    def test_raises_error_when_correlation_time_is_too_high(self):
        path = "./files/bulk_water/classical"

        topology_name = "revPBE0-D3-w64-T300K-1bar"
        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True, topology_file_name=topology_name)
        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )

        with pytest.raises(analysis.UnphysicalValue):
            simulation.compute_mean_squared_displacement(["O", "H"], correlation_time=100000)
    def test_returns_profile_in_z_direction(self):

        path = "./files/water_on_graphene"

        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True)
        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )
        simulation.compute_density_profile(["O", "H"], direction="z")

        assert simulation.density_profiles.get("O H - z")
Пример #5
0
    def test_raises_error_when_species_not_found(self):
        path = "./files/bulk_water/classical"

        topology_name = "revPBE0-D3-w64-T300K-1bar"
        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True, topology_file_name=topology_name)

        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )

        with pytest.raises(analysis.KeyNotFound):
            simulation.compute_rdf("O", "X")
Пример #6
0
    def test_returns_error_for_three_periodic_directions(self):
        path = "./files/bulk_water/classical"

        topology_name = "revPBE0-D3-w64-T300K-1bar"
        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True, topology_file_name=topology_name)

        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )

        with pytest.raises(analysis.UnphysicalValue):
            simulation.get_water_contact_layer_on_interface()
Пример #7
0
        def test_raises_error_when_unknown_fluid(self):
            path = "./files/bulk_water/classical"

            topology_name = "revPBE0-D3-w64-T300K-1bar"
            simulation = analysis.Simulation(path)

            simulation.read_in_simulation_data(
                read_positions=True, topology_file_name=topology_name)

            with pytest.raises(utils.UndefinedOption):
                correction = (
                    utils.
                    compute_finite_size_correction_for_diffusion_coefficient_of_bulk_fluid(
                        simulation.topology, fluid="hexane", temperature=330))
Пример #8
0
        def test_returns_correction(self):
            path = "./files/bulk_water/classical"

            topology_name = "revPBE0-D3-w64-T300K-1bar"
            simulation = analysis.Simulation(path)

            simulation.read_in_simulation_data(
                read_positions=True, topology_file_name=topology_name)

            correction = (
                utils.
                compute_finite_size_correction_for_diffusion_coefficient_of_bulk_fluid(
                    simulation.topology, fluid="water", temperature=330))

            assert correction
Пример #9
0
    def test_raises_error_when_number_of_blocks_is_too_high(self):
        path = "./files/water_in_carbon_nanotube/m12_n12/quantum"

        simulation = analysis.Simulation(path)
        simulation.read_in_simulation_data(read_positions=False, read_summed_forces=True)

        with pytest.raises(analysis.UnphysicalValue):
            simulation.compute_friction_coefficient_via_green_kubo(
                time_between_frames=1,
                correlation_time=1000,
                number_of_blocks=3000,
                start_time=1000,
                end_time=4500,
                frame_frequency=1,
            )
Пример #10
0
    def test_raises_error_when_unknown_dimension(self):
        path = "./files/bulk_water/classical"

        topology_name = "revPBE0-D3-w64-T300K-1bar"
        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True, topology_file_name=topology_name)

        oxygens = simulation.position_universes[0].select_atoms("name O")

        vectors_oxygen_1_to_others = oxygens.positions - oxygens[0].position

        with pytest.raises(utils.UndefinedOption):
            vectors_MIC = utils.apply_minimum_image_convention_to_interatomic_vectors(
                vectors_oxygen_1_to_others, simulation.topology.cell, dimension="w"
            )
Пример #11
0
    def test_returns_MSD_for_bulk_water_based_on_water_COM(self):
        path = "./files/bulk_water/classical"

        topology_name = "revPBE0-D3-w64-T300K-1bar"
        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True, topology_file_name=topology_name)

        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )
        simulation.compute_mean_squared_displacement(
            ["O", "H"], correlation_time=200, number_of_blocks=5
        )

        assert simulation.mean_squared_displacements.get("O H - ct: 200")
Пример #12
0
    def test_returns_reorientational_relaxation_time_for_bulk_water_full(self):
        path = "./files/bulk_water/classical"

        topology_name = "revPBE0-D3-w64-T300K-1bar"
        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True, topology_file_name=topology_name)

        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )

        simulation.compute_water_reorientational_relaxation_time(regime="Full", correlation_time=1000, number_of_blocks=1)
        
        breakpoint()
        assert simulation.reorientational_relaxation_time.get('reg: Full; ct: 1000')
Пример #13
0
    def test_returns_profile_in_radial_direction_OH(self):
        path = "./files/water_in_carbon_nanotube/m12_n12/classical"

        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True)
        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )
        simulation.set_pbc_dimensions("z")

        simulation.compute_water_orientation_profile(water_vector="O-H",frame_frequency=10)

        assert (
            np.max(simulation.water_orientations_spatially_resolved["O-H"][0][:, 0]) <= 1
            and np.min(simulation.water_orientations_spatially_resolved["O-H"][0][:, 0]) >= -1
        )
Пример #14
0
    def test_returns_profile_in_z_direction(self):
        path = "./files/water_on_graphene"

        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True)
        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )
        simulation.set_pbc_dimensions("xy")

        simulation.compute_water_orientation_profile(frame_frequency=10)

        assert (
            np.max(simulation.water_orientations_spatially_resolved["Dipole"][0][:, 0]) <= 1
            and np.min(simulation.water_orientations_spatially_resolved["Dipole"][0][:, 0]) >= -1
        )
Пример #15
0
    def test_returns_contact_layer_for_one_dimensions(self):
        path = "./files/water_in_carbon_nanotube/m12_n12/classical"

        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True)

        simulation.set_pbc_dimensions("z")

        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )

        simulation.compute_density_profile(["O", "H"], direction="radial z")

        spatial_expansion_contact_layer = simulation.get_water_contact_layer_on_interface()

        assert spatial_expansion_contact_layer > 0
Пример #16
0
    def test_returns_reorientational_relaxation_time_for_nanotube_in_bulk_regime(self):
        path = "./files/water_in_carbon_nanotube/m12_n12/classical"

        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True)

        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )

        simulation.set_pbc_dimensions("z")

        simulation.compute_density_profile(["O", "H"], direction="radial z")


        simulation.compute_water_reorientational_relaxation_time(regime="Bulk", correlation_time=1000, number_of_blocks=1)
        
        assert simulation.reorientational_relaxation_time.get('reg: Bulk; ct: 1000')
Пример #17
0
    def test_returns_reorientational_relaxation_time_for_graphene_full(self):
        path = "./files/water_on_graphene"

        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True)

        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )

        simulation.set_pbc_dimensions("xy")

        simulation.compute_density_profile(["O", "H"], direction="z")


        simulation.compute_water_reorientational_relaxation_time(regime="Full", correlation_time=1000, number_of_blocks=1)
        
        assert simulation.reorientational_relaxation_time.get('reg: Full; ct: 1000')
Пример #18
0
    def test_returns_adjusted_vectors_2D(self):
        path = "./files/bulk_water/classical"

        topology_name = "revPBE0-D3-w64-T300K-1bar"
        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True,
                                           topology_file_name=topology_name)

        oxygens = simulation.position_universes[0].select_atoms("name O")

        vectors_oxygen_1_to_others = oxygens.positions - oxygens[0].position

        vectors_MIC = utils.apply_minimum_image_convention_to_interatomic_vectors(
            vectors_oxygen_1_to_others,
            simulation.topology.cell,
        )

        assert (np.min(vectors_MIC) >= -simulation.topology.cell[0][0] / 2
                and np.max(vectors_MIC) <= simulation.topology.cell[0][0] / 2)
Пример #19
0
    def test_returns_pandas_dataframe_for_bulk_water(self):
        path = "./files/bulk_water/classical"

        topology_name = "revPBE0-D3-w64-T300K-1bar"
        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True,
                                           topology_file_name=topology_name)

        hydrogen_bonding_analysis = hydrogen_bonding.HydrogenBonding(
            simulation.position_universes[0], simulation.topology)

        hydrogen_bonding_analysis.find_acceptor_donor_pairs(
            start_frame=0,
            end_frame=-1,
            frame_frequency=10,
            time_between_frames=20,
            pbc_dimensions="xyz",
        )

        assert np.max(hydrogen_bonding_analysis.dataframe["Time"]) == 2000
Пример #20
0
    def test_returns_diffusion_coefficient(self):

        path = "./files/water_in_carbon_nanotube/m12_n12/classical"

        simulation = analysis.Simulation(path)
        simulation.read_in_simulation_data(
            read_positions=True, read_velocities=True, read_summed_forces=False
        )

        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )

        simulation.compute_diffusion_coefficient_via_green_kubo(
            species=["O"],
            correlation_time=1000,
            number_of_blocks=3,
            start_time=1000,
            end_time=20000,
        )
        assert len(simulation.diffusion_coefficients_via_GK["O - ct: 1000"]) == 3
Пример #21
0
    def test_returns_correct_autocorrelation_function(self):
        path = "./files/water_in_carbon_nanotube/m12_n12/classical"

        simulation = analysis.Simulation(path)
        simulation.read_in_simulation_data(read_positions=True, read_summed_forces=True)

        simulation.set_pbc_dimensions(pbc_dimensions="z")
        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )

        simulation.compute_friction_coefficient_via_green_kubo(
            time_between_frames=1,
            correlation_time=1000,
            number_of_blocks=3,
            start_time=1000,
            end_time=4500,
            frame_frequency=1,
        )

        assert simulation.friction_coefficients.get("ct: 1000")
Пример #22
0
    def test_returns_pandas_dataframe_for_carbon_nanotube(self):

        path = "./files/water_in_carbon_nanotube/m12_n12/classical"

        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True)

        simulation.set_pbc_dimensions("z")

        hydrogen_bonding_analysis = hydrogen_bonding.HydrogenBonding(
            simulation.position_universes[0], simulation.topology)

        hydrogen_bonding_analysis.find_acceptor_donor_pairs(
            start_frame=0,
            end_frame=-1,
            frame_frequency=10,
            time_between_frames=20,
            pbc_dimensions="z",
        )

        assert np.max(hydrogen_bonding_analysis.dataframe["Time"]) == 2000
Пример #23
0
    def test_returns_pandas_dataframe_for_graphene(self):

        path = "./files/water_on_graphene/"

        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True)

        simulation.set_pbc_dimensions("xy")

        hydrogen_bonding_analysis = hydrogen_bonding.HydrogenBonding(
            simulation.position_universes[0], simulation.topology)

        hydrogen_bonding_analysis.heavy_atoms_analysis(
            start_frame=0,
            end_frame=-1,
            frame_frequency=10,
            time_between_frames=20,
            pbc_dimensions="xy",
            spatial_extent_contact_layer=3.65)

        assert len(
            np.unique(hydrogen_bonding_analysis.
                      heavy_atoms_dataframe["Species"])) == 2
Пример #24
0
    def test_returns_same_result_as_vmd(self):

        path = "./files/bulk_water/classical"

        vmd_data = pandas.read_csv(
            os.path.join(path, "rdf_vmd.dat"), sep=r"\s", engine="python", header=None
        )

        topology_name = "revPBE0-D3-w64-T300K-1bar"
        simulation = analysis.Simulation(path)

        simulation.read_in_simulation_data(read_positions=True, topology_file_name=topology_name)

        simulation.set_sampling_times(
            start_time=0, end_time=-1, frame_frequency=1, time_between_frames=20
        )
        simulation.compute_rdf("O", "O", spatial_range=6.2, spatial_resolution=309)

        assert (
            mean_squared_error(
                vmd_data[1][1::], simulation.radial_distribution_functions["O-O"][1], squared=False
            )
            < 2e-2
        )
Пример #25
0
        def test_returns_correct_center_of_masses(self):
            path = "./files/bulk_water/classical"

            topology_name = "revPBE0-D3-w64-T300K-1bar"
            simulation = analysis.Simulation(path)

            simulation.read_in_simulation_data(
                read_positions=True, topology_file_name=topology_name)

            water_atoms = simulation.position_universes[0].select_atoms(
                "name O H")

            water_atoms.pack_into_box(
                box=simulation.topology.get_cell_lengths_and_angles(),
                inplace=True)

            water_molecule_58 = water_atoms[174:177]

            center_of_mass_MIC = utils.get_center_of_mass_of_atoms_in_accordance_with_MIC(
                water_molecule_58, simulation.topology, dimension="xyz")

            assert np.all(center_of_mass_MIC <= simulation.topology.
                          get_cell_lengths_and_angles()[0:3]) and np.all(
                              center_of_mass_MIC >= np.zeros(3))