[][src]Struct chemfiles::Topology

pub struct Topology { /* fields omitted */ }

A Topology contains the definition of all the atoms in the system, and the liaisons between the atoms (bonds, angles, dihedrals, ...). It will also contain all the residues information if it is available.

Methods

impl Topology
[src]

Create a new empty topology.

Example

let topology = Topology::new().unwrap();
assert_eq!(topology.size(), Ok(0));

Get a copy of the atom at index index from this topology.

Example

let mut topology = Topology::new().unwrap();
topology.resize(6).unwrap();

let atom = topology.atom(4).unwrap();
assert_eq!(atom.name(), Ok(String::new()));

Get the current number of atoms in this topology.

Example

let mut topology = Topology::new().unwrap();
assert_eq!(topology.size(), Ok(0));

topology.resize(6).unwrap();
assert_eq!(topology.size(), Ok(6));

Resize this topology to hold natoms atoms, inserting dummy atoms if the new size if bigger than the old one.

Example

let mut topology = Topology::new().unwrap();
assert_eq!(topology.size(), Ok(0));

topology.resize(6).unwrap();
assert_eq!(topology.size(), Ok(6));

Add an Atom at the end of this topology

Example

let mut topology = Topology::new().unwrap();
topology.add_atom(&Atom::new("Mg").unwrap()).unwrap();

let atom = topology.atom(0).unwrap();
assert_eq!(atom.name(), Ok(String::from("Mg")));

Remove an Atom from this topology by index. This modify all the other atoms indexes.

Example

let mut topology = Topology::new().unwrap();
topology.resize(9).unwrap();
assert_eq!(topology.size(), Ok(9));

topology.remove(7).unwrap();
assert_eq!(topology.size(), Ok(8));

Get the number of bonds in the topology.

Example

let mut topology = Topology::new().unwrap();
assert_eq!(topology.bonds_count(), Ok(0));

topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();

topology.add_bond(0, 1).unwrap();
topology.add_bond(2, 1).unwrap();
topology.add_bond(2, 3).unwrap();
assert_eq!(topology.bonds_count(), Ok(3));

Get the number of angles in the topology.

Example

let mut topology = Topology::new().unwrap();
assert_eq!(topology.angles_count(), Ok(0));

topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();

topology.add_bond(0, 1).unwrap();
topology.add_bond(2, 1).unwrap();
topology.add_bond(2, 3).unwrap();
assert_eq!(topology.angles_count(), Ok(2));

Get the number of dihedral angles in the topology.

Example

let mut topology = Topology::new().unwrap();
assert_eq!(topology.dihedrals_count(), Ok(0));

topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();

topology.add_bond(0, 1).unwrap();
topology.add_bond(2, 1).unwrap();
topology.add_bond(2, 3).unwrap();
assert_eq!(topology.dihedrals_count(), Ok(1));

Get the number of improper dihedral angles in the topology.

Example

let mut topology = Topology::new().unwrap();
assert_eq!(topology.dihedrals_count(), Ok(0));

topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();

topology.add_bond(0, 1).unwrap();
topology.add_bond(0, 2).unwrap();
topology.add_bond(0, 3).unwrap();
assert_eq!(topology.impropers_count(), Ok(1));

Get the list of bonds in the topology.

Example

let mut topology = Topology::new().unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();

topology.add_bond(0, 1).unwrap();
topology.add_bond(2, 1).unwrap();
topology.add_bond(2, 3).unwrap();
assert_eq!(topology.bonds(), Ok(vec![[0, 1], [1, 2], [2, 3]]));

Get the list of angles in the topology.

Example

let mut topology = Topology::new().unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();

topology.add_bond(0, 1).unwrap();
topology.add_bond(2, 1).unwrap();
topology.add_bond(2, 3).unwrap();
assert_eq!(topology.angles(), Ok(vec![[0, 1, 2], [1, 2, 3]]));

Get the list of dihedral angles in the topology.

Example

let mut topology = Topology::new().unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();

topology.add_bond(0, 1).unwrap();
topology.add_bond(2, 1).unwrap();
topology.add_bond(2, 3).unwrap();

assert_eq!(topology.dihedrals(), Ok(vec![[0, 1, 2, 3]]));

Get the list of improper dihedral angles in the topology.

Example

let mut topology = Topology::new().unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();

topology.add_bond(0, 1).unwrap();
topology.add_bond(0, 2).unwrap();
topology.add_bond(0, 3).unwrap();

assert_eq!(topology.impropers(), Ok(vec![[1, 0, 2, 3]]));

Add a bond between the atoms at indexes i and j in the topology.

Example

let mut topology = Topology::new().unwrap();
assert_eq!(topology.bonds_count(), Ok(0));

topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();

topology.add_bond(0, 1).unwrap();
topology.add_bond(0, 2).unwrap();
assert_eq!(topology.bonds_count(), Ok(2));

Remove any existing bond between the atoms at indexes i and j in this topology.

This function does nothing if there is no bond between i and j.

Example

let mut topology = Topology::new().unwrap();
assert_eq!(topology.bonds_count(), Ok(0));

topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();
topology.add_atom(&Atom::new("F").unwrap()).unwrap();

topology.add_bond(0, 1).unwrap();
topology.add_bond(1, 2).unwrap();
assert_eq!(topology.bonds_count(), Ok(2));

topology.remove_bond(0, 1).unwrap();
assert_eq!(topology.bonds_count(), Ok(1));

// Removing a bond that does not exists
topology.remove_bond(0, 2).unwrap();
assert_eq!(topology.bonds_count(), Ok(1));

Get a copy of the residue at index index from this topology.

The residue index in the topology is not always the same as the residue id.

Example

let mut topology = Topology::new().unwrap();
topology.add_residue(&Residue::new("water").unwrap()).unwrap();

let residue = topology.residue(0).unwrap();
assert_eq!(residue.name(), Ok(String::from("water")));

Get a copy of the residue containing the atom at index index in this topology, if any.

Example

let mut topology = Topology::new().unwrap();
topology.resize(8).unwrap();

let mut residue = Residue::new("water").unwrap();
residue.add_atom(0).unwrap();
residue.add_atom(1).unwrap();
residue.add_atom(2).unwrap();
topology.add_residue(&residue).unwrap();

let residue = topology.residue_for_atom(0).unwrap().unwrap();
assert_eq!(residue.name(), Ok(String::from("water")));

let residue = topology.residue_for_atom(6).unwrap();
assert!(residue.is_none());

Get the number of residues in this topology.

Example

let mut topology = Topology::new().unwrap();
assert_eq!(topology.residues_count(), Ok(0));

topology.add_residue(&Residue::with_id("water", 0).unwrap()).unwrap();
topology.add_residue(&Residue::with_id("protein", 1).unwrap()).unwrap();
assert_eq!(topology.residues_count(), Ok(2));

Add a residue to this topology.

The residue id must not already be in the topology, and the residue must contain only atoms that are not already in another residue.

Example

let mut topology = Topology::new().unwrap();
topology.add_residue(&Residue::new("water").unwrap()).unwrap();

let residue = topology.residue(0).unwrap();
assert_eq!(residue.name(), Ok(String::from("water")));

Check if the two residues first and second from the topology are linked together, i.e. if there is a bond between one atom in the first residue and one atom in the second one.

Example

let mut topology = Topology::new().unwrap();

topology.add_residue(&Residue::with_id("water", 0).unwrap()).unwrap();
topology.add_residue(&Residue::with_id("protein", 1).unwrap()).unwrap();

let first = topology.residue(0).unwrap();
let second = topology.residue(1).unwrap();
assert_eq!(topology.are_linked(&first, &second), Ok(false));

Trait Implementations

impl Drop for Topology
[src]

Executes the destructor for this type. Read more

impl Clone for Topology
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Auto Trait Implementations

impl !Send for Topology

impl !Sync for Topology

Blanket Implementations

impl<T> From for T
[src]

Performs the conversion.

impl<T, U> Into for T where
    U: From<T>, 
[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.

impl<T> Borrow for T where
    T: ?Sized
[src]

Immutably borrows from an owned value. Read more

impl<T> Any for T where
    T: 'static + ?Sized
[src]

🔬 This is a nightly-only experimental API. (get_type_id)

this method will likely be replaced by an associated static

Gets the TypeId of self. Read more

impl<T> BorrowMut for T where
    T: ?Sized
[src]

Mutably borrows from an owned value. Read more

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

🔬 This is a nightly-only experimental API. (try_from)

Performs the conversion.