Struct chemfiles::TopologyRef
source · pub struct TopologyRef<'a> { /* private fields */ }
Expand description
An analog to a reference to a topology (&Topology
)
Methods from Deref<Target = Topology>§
sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Get the current number of atoms in this topology.
Example
let mut topology = Topology::new();
assert_eq!(topology.size(), 0);
topology.resize(6);
assert_eq!(topology.size(), 6);
sourcepub fn bonds_count(&self) -> usize
pub fn bonds_count(&self) -> usize
Get the number of bonds in the topology.
Example
let mut topology = Topology::new();
assert_eq!(topology.bonds_count(), 0);
topology.resize(4);
topology.add_bond(0, 1);
topology.add_bond(2, 1);
topology.add_bond(2, 3);
assert_eq!(topology.bonds_count(), 3);
sourcepub fn angles_count(&self) -> usize
pub fn angles_count(&self) -> usize
Get the number of angles in the topology.
Example
let mut topology = Topology::new();
assert_eq!(topology.angles_count(), 0);
topology.resize(4);
topology.add_bond(0, 1);
topology.add_bond(2, 1);
topology.add_bond(2, 3);
assert_eq!(topology.angles_count(), 2);
sourcepub fn dihedrals_count(&self) -> usize
pub fn dihedrals_count(&self) -> usize
Get the number of dihedral angles in the topology.
Example
let mut topology = Topology::new();
assert_eq!(topology.dihedrals_count(), 0);
topology.resize(4);
topology.add_bond(0, 1);
topology.add_bond(2, 1);
topology.add_bond(2, 3);
assert_eq!(topology.dihedrals_count(), 1);
sourcepub fn impropers_count(&self) -> usize
pub fn impropers_count(&self) -> usize
Get the number of improper dihedral angles in the topology.
Example
let mut topology = Topology::new();
assert_eq!(topology.dihedrals_count(), 0);
topology.resize(4);
topology.add_bond(0, 1);
topology.add_bond(0, 2);
topology.add_bond(0, 3);
assert_eq!(topology.impropers_count(), 1);
sourcepub fn bonds(&self) -> Vec<[usize; 2]>
pub fn bonds(&self) -> Vec<[usize; 2]>
Get the list of bonds in the topology.
Example
let mut topology = Topology::new();
topology.resize(4);
topology.add_bond(0, 1);
topology.add_bond(2, 1);
topology.add_bond(2, 3);
assert_eq!(topology.bonds(), vec![[0, 1], [1, 2], [2, 3]]);
sourcepub fn angles(&self) -> Vec<[usize; 3]>
pub fn angles(&self) -> Vec<[usize; 3]>
Get the list of angles in the topology.
Example
let mut topology = Topology::new();
topology.resize(4);
topology.add_bond(0, 1);
topology.add_bond(2, 1);
topology.add_bond(2, 3);
assert_eq!(topology.angles(), vec![[0, 1, 2], [1, 2, 3]]);
sourcepub fn dihedrals(&self) -> Vec<[usize; 4]>
pub fn dihedrals(&self) -> Vec<[usize; 4]>
Get the list of dihedral angles in the topology.
Example
let mut topology = Topology::new();
topology.resize(4);
topology.add_bond(0, 1);
topology.add_bond(2, 1);
topology.add_bond(2, 3);
assert_eq!(topology.dihedrals(), vec![[0, 1, 2, 3]]);
sourcepub fn impropers(&self) -> Vec<[usize; 4]>
pub fn impropers(&self) -> Vec<[usize; 4]>
Get the list of improper dihedral angles in the topology.
Example
let mut topology = Topology::new();
topology.resize(4);
topology.add_bond(0, 1);
topology.add_bond(0, 2);
topology.add_bond(0, 3);
assert_eq!(topology.impropers(), vec![[1, 0, 2, 3]]);
sourcepub fn bond_order(&self, i: usize, j: usize) -> BondOrder
pub fn bond_order(&self, i: usize, j: usize) -> BondOrder
Get the bond order for the bond between the atoms at indexes i
and
j
.
Example
let mut topology = Topology::new();
assert_eq!(topology.bonds_count(), 0);
topology.resize(2);
topology.add_bond_with_order(0, 1, BondOrder::Double);
assert_eq!(topology.bond_order(0, 1), BondOrder::Double);
sourcepub fn bond_orders(&self) -> Vec<BondOrder>
pub fn bond_orders(&self) -> Vec<BondOrder>
Get the bond order for all the bonds in the topology
Example
let mut topology = Topology::new();
assert_eq!(topology.bonds_count(), 0);
topology.resize(3);
topology.add_bond_with_order(0, 1, BondOrder::Double);
topology.add_bond_with_order(0, 2, BondOrder::Single);
assert_eq!(topology.bond_orders(), &[BondOrder::Double, BondOrder::Single]);
sourcepub fn residue(&self, index: usize) -> Option<ResidueRef<'_>>
pub fn residue(&self, index: usize) -> Option<ResidueRef<'_>>
Get a reference to 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();
topology.add_residue(&Residue::new("water")).unwrap();
let residue = topology.residue(0).unwrap();
assert_eq!(residue.name(), "water");
sourcepub fn residue_for_atom(&self, index: usize) -> Option<ResidueRef<'_>>
pub fn residue_for_atom(&self, index: usize) -> Option<ResidueRef<'_>>
Get a copy of the residue containing the atom at index index
in this
topology, if any.
Example
let mut topology = Topology::new();
topology.resize(8);
let mut residue = Residue::new("water");
residue.add_atom(0);
residue.add_atom(1);
residue.add_atom(2);
topology.add_residue(&residue).unwrap();
let residue = topology.residue_for_atom(0).unwrap();
assert_eq!(residue.name(), "water");
assert!(topology.residue_for_atom(6).is_none());
sourcepub fn residues_count(&self) -> u64
pub fn residues_count(&self) -> u64
Get the number of residues in this topology.
Example
let mut topology = Topology::new();
assert_eq!(topology.residues_count(), 0);
topology.add_residue(&Residue::with_id("water", 0)).unwrap();
topology.add_residue(&Residue::with_id("protein", 1)).unwrap();
assert_eq!(topology.residues_count(), 2);
sourcepub fn are_linked(&self, first: &Residue, second: &Residue) -> bool
pub fn are_linked(&self, first: &Residue, second: &Residue) -> bool
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();
topology.add_residue(&Residue::with_id("water", 0)).unwrap();
topology.add_residue(&Residue::with_id("protein", 1)).unwrap();
let first = topology.residue(0).unwrap();
let second = topology.residue(1).unwrap();
assert_eq!(topology.are_linked(&first, &second), false);