Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/biotite/structure/bonds.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _without_aromaticity(self):
# Create BondType IntEnum dynamically from Rust enum members
BondType = IntEnum(
"BondType",
{name: value for name, value in bond_type_members().items()},
bond_type_members(),
module=__name__,
)
BondType.__doc__ = """
Expand Down
46 changes: 23 additions & 23 deletions src/rust/structure/bonds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pyo3::exceptions;
use pyo3::prelude::*;
use pyo3::types::{PyModule, PySet, PyTuple};
use smallvec::SmallVec;
use std::collections::{HashMap, HashSet};
use std::collections::HashSet;
use std::convert::TryFrom;

const TYPICAL_MAX_BONDS_PER_ATOM: usize = 4;
Expand Down Expand Up @@ -37,29 +37,29 @@ impl BondType {
}
}

/// Return the members of the :class:`BondType` enum as key-value pairs.
///
/// Returns
/// -------
/// members : list of tuples
/// The members of the :class:`BondType` enum as key-value pairs.
#[pyfunction]
pub fn bond_type_members() -> HashMap<String, u8> {
let mut map = HashMap::new();
map.insert("ANY".to_string(), BondType::Any as u8);
map.insert("SINGLE".to_string(), BondType::Single as u8);
map.insert("DOUBLE".to_string(), BondType::Double as u8);
map.insert("TRIPLE".to_string(), BondType::Triple as u8);
map.insert("QUADRUPLE".to_string(), BondType::Quadruple as u8);
map.insert(
"AROMATIC_SINGLE".to_string(),
BondType::AromaticSingle as u8,
);
map.insert(
"AROMATIC_DOUBLE".to_string(),
BondType::AromaticDouble as u8,
);
map.insert(
"AROMATIC_TRIPLE".to_string(),
BondType::AromaticTriple as u8,
);
map.insert("COORDINATION".to_string(), BondType::Coordination as u8);
map.insert("AROMATIC".to_string(), BondType::Aromatic as u8);
map
pub fn bond_type_members() -> Vec<(String, u8)> {
[
("ANY", BondType::Any),
("SINGLE", BondType::Single),
("DOUBLE", BondType::Double),
("TRIPLE", BondType::Triple),
("QUADRUPLE", BondType::Quadruple),
("AROMATIC_SINGLE", BondType::AromaticSingle),
("AROMATIC_DOUBLE", BondType::AromaticDouble),
("AROMATIC_TRIPLE", BondType::AromaticTriple),
("COORDINATION", BondType::Coordination),
("AROMATIC", BondType::Aromatic),
]
.iter()
.map(|(name, member)| (name.to_string(), *member as u8))
.collect()
}

impl TryFrom<u8> for BondType {
Expand Down
2 changes: 1 addition & 1 deletion tests/interface/test_rdkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_kekulization():
or [
struc.BondType.AROMATIC_SINGLE
if btype == struc.BondType.AROMATIC_DOUBLE
else struc.BondType.AROMATIC_SINGLE
else struc.BondType.AROMATIC_DOUBLE
for btype in test_bond_types
]
== ref_bond_types.tolist()
Expand Down
8 changes: 8 additions & 0 deletions tests/structure/test_bonds.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,11 @@ def test_pickle(bond_list):
"""
restored = pickle.loads(pickle.dumps(bond_list))
assert restored == bond_list


def test_bond_type_order():
"""
Check that :class:`BondType` members are ordered by their values.
"""
values = [member.value for member in struc.BondType]
assert values == sorted(values)
Loading