Skip to content

Implement Trj method for selecting a subset of atoms #126

@matteobecchi

Description

@matteobecchi

Something along the lines of

import MDAnalysis as mda
import numpy as np
from MDAnalysis.coordinates.memory import MemoryReader

def expensive_atom_selection(trj: Trj, selection: str) -> Trj:
    """Create a trj with a selection of atoms."""
    oxygen_atoms = trj.universe.select_atoms(selection)
    coords = []
    for ts in trj.universe.trajectory:
        coords.append(oxygen_atoms.positions.copy())
    u_oxygen = mda.Merge(oxygen_atoms)
    u_oxygen.load_new(np.array(coords), format=MemoryReader)
    return Trj(u_oxygen)

?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions