Skip to content

Shared methods could be defined as traits #34

@jbarnoud

Description

@jbarnoud

The Frame and the Topology structs share methods to access and modify the topology of a system. These methods, defined as a trait, would allow writing functions that can accept both a Frame and a Topology. Having more than one trait would also allow sharing methods with TopologyRef.

From a quick look at the documentation, I would suggest two traits:

  • AccessTopology could be defined for Topology, TopologyRef, and Frame. It could have the following methods:
    • atom
    • size
  • MulateTopology could be defined for Topology and Frame and have:
    • atom_mut
    • resize
    • add_atom
    • remove
    • add_bond
    • add_bond_with_order
    • remove_bond
    • add_residue
    • clear_bonds

Counterintuitively, neither Topology nor TopologyRef have iter_atoms, which would work well in the AccessTopology trait. Since Frame does not have any method to access residues, bonds, angles, or dihedrals (bond, angle, and dihedral return the measure of the connection, not the connection itself), the AccessTopology trait could also be named AccessAtoms.

With these traits, it would be possible to write code like:

fn do_something_with_the_atoms(source: &impl AccessTopology) {
    for atom in source.iter_atoms() {
        // something
    }
}

fn main() {
    let frame: Frame = ...;
    let topology: Topology = ...;
    do_something_with_the_atoms(frame);
    do_something_with_the_atoms(topology);
}

If there is interest, I'd be happy to work on a pull request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions