Exemple #1
0
def read_all_files(pathname: Path,
                   index: int = 0,
                   pattern: str = "dump-Trimer-*.gsd"
                   ) -> List[Tuple[Variables, HoomdFrame]]:
    """Read all the gsd files from a directory given a pattern.

    A utility function for getting reading all the gsd files from a given directory,
    with the ability to use a pattern to match a subset.

    Args:
        pathname: The directory from which the files will be read
        index: The index of the snapshot to read for each trajectory.
        pattern: The pattern passed to the glob function to match.

    Returns:
        A list of tuples containing the variables for a configuration, established from the filename,
        along with the frame.

    """
    pathname = Path(pathname)
    snapshots = []
    for filename in sorted(glob.glob(str(pathname / pattern))):
        logger.debug("Reading %s", Path(filename).stem)
        with gsd.hoomd.open(str(filename)) as trj:
            try:
                snapshots.append(
                    (get_filename_vars(filename), HoomdFrame(trj[index])))
            except IndexError:
                continue
    if not snapshots:
        logger.warning(
            "There were no files found with a configuration at index %s",
            index)
    return snapshots
    def test_rot_methods(self, dynamics_class, trajectory, step, method):
        snap = HoomdFrame(trajectory[step])
        dynamics_class.add_frame(snap)
        quantity = getattr(dynamics_class, method)()

        if step == 0:
            assert np.allclose(quantity, 0, atol=2e-5)
        else:
            assert np.all(quantity >= 0)
 def test_rotations(self, dynamics_class, trajectory, step):
     snap = HoomdFrame(trajectory[step])
     dynamics_class.add_frame(snap)
     rotations = dynamics_class.compute_rotation()
     assert rotations.shape == (dynamics_class.num_particles, )
     if step == 0:
         assert np.allclose(rotations, 0.0, atol=EPS)
     else:
         assert np.all(rotations >= 0.0)
 def test_displacements(self, dynamics_class, trajectory, step):
     snap = HoomdFrame(trajectory[step])
     dynamics_class.add_frame(snap)
     displacement = dynamics_class.compute_displacement()
     assert displacement.shape == (dynamics_class.num_particles, )
     if step == 0:
         assert np.all(displacement == 0.0)
     else:
         assert np.all(displacement >= 0.0)
def dynamics_class(trajectory):
    snap = HoomdFrame(trajectory[0])
    return dynamics.Dynamics(
        snap.timestep,
        snap.box,
        snap.position,
        snap.orientation,
        wave_number=4.0,
    )
Exemple #6
0
def read_file(
    index: int = 0,
    pressure: float = 1.00,
    temperature: float = 0.40,
    crystal: str = "p2",
    directory: Optional[Path] = None,
) -> HoomdFrame:
    if directory is None:
        directory = Path("../data/simulations/interface/output")
    fname = f"dump-Trimer-P{pressure:.2f}-T{temperature:.2f}-{crystal}.gsd"
    with gsd.hoomd.open(str(directory / fname), "rb") as trj:
        return HoomdFrame(trj[index])
Exemple #7
0
def labelled_config(infile, index):
    """Plot an input configuration indicating the labelling scheme.

    This plots the configuration with an overlay indicating the regions in which
    particles are classified as liquid (blue) and the regions where they are classified
    as crystal (red).

    """
    with gsd.hoomd.open(infile) as trj:
        snap = HoomdFrame(trj[index])

    fig = plot_labelled_config(snap)

    fig.output_backend = "svg"
    export_svgs(fig, "figures/labelled_config.png", height=1600, width=3200)
Exemple #8
0
def read_all_files(
    pathname: Path, index: int = 0, pattern: str = "dump-Trimer-*.gsd"
) -> List[Tuple[Variables, HoomdFrame]]:
    pathname = Path(pathname)
    snapshots = []
    for filename in glob.glob(str(pathname / pattern)):
        logger.debug("Reading %s", Path(filename).stem)
        with gsd.hoomd.open(str(filename)) as trj:
            try:
                snapshots.append((get_filename_vars(filename), HoomdFrame(trj[index])))
            except IndexError:
                continue
    if not snapshots:
        logger.warning(
            "There were no files found with a configuration at index %s", index
        )
    return snapshots
Exemple #9
0
def read_file(
    index: int = 0,
    pressure: float = 1.00,
    temperature: float = 0.40,
    crystal: str = "p2",
    prefix: str = "dump",
) -> HoomdFrame:

    data_dir = Path("../data/simulation/dataset/output")
    fname = f"{prefix}-Trimer-P{pressure:.2f}-T{temperature:.2f}-{crystal}.gsd"
    filename = data_dir / fname
    if not filename.exists():
        raise FileNotFoundError(read_file)
    with gsd.hoomd.open(str(filename)) as trj:
        try:
            return HoomdFrame(trj[index])
        except IndexError:
            raise IndexError(
                f"Index {index} not found in trajectory of length {len(trj)}.")
Exemple #10
0
def read_all_files(directory: Path,
                   index: int = 0,
                   glob: str = "dump-*") -> List[SnapshotData]:
    directory = Path(directory)
    snapshots = []
    for file in directory.glob(glob):
        with gsd.hoomd.open(str(file), "rb") as trj:
            try:
                snap = HoomdFrame(trj[index])
            except IndexError:
                logger.warning(
                    "Index %d in input file %s doesn't exist, continuing...",
                    index,
                    file.name,
                )
            snapshots.append(
                SnapshotData.from_variables(snap,
                                            util.get_filename_vars(file)))
    return snapshots
Exemple #11
0
def test_traj(gsd_trajectory):
    with gsd.hoomd.open(str(gsd_trajectory)) as trj:
        HoomdFrame(trj[0])
 def test_alpha_methods(self, dynamics_class, trajectory, step, method):
     snap = HoomdFrame(trajectory[step])
     dynamics_class.add_frame(snap)
     quantity = getattr(dynamics_class, method)()
     assert isinstance(float(quantity), float)