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
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ version = "0.0.0"
edition = "2018"

[dependencies]
numpy = "0.25"
ndarray = "0.16"
numpy = "0.27"
ndarray = "0.17"
num-traits = "0.2"

[dependencies.pyo3]
version = "0.25"
version = "0.27"
features = ["extension-module"]

[lib]
Expand Down
9 changes: 7 additions & 2 deletions src/biotite/structure/atoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,11 @@ def concatenate(atoms):
has_bonds = False
for element in atoms:
if element_type is None:
if not isinstance(element, (AtomArray, AtomArrayStack)):
raise TypeError(
"Expected 'AtomArray' or 'AtomArrayStack', "
f"but got '{type(element).__name__}'"
)
element_type = type(element)
else:
if not isinstance(element, element_type):
Expand All @@ -1384,9 +1389,9 @@ def concatenate(atoms):
if element.bonds is not None:
has_bonds = True

if element_type == AtomArray:
if issubclass(element_type, AtomArray):
concat_atoms = AtomArray(length)
elif element_type == AtomArrayStack:
else:
concat_atoms = AtomArrayStack(depth, length)
concat_atoms.coord = np.concatenate([element.coord for element in atoms], axis=-2)
for category in common_categories:
Expand Down
4 changes: 2 additions & 2 deletions src/biotite/structure/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ def filter_first_altloc(atoms, altloc_ids):
# And filter all atoms for each residue with the first altloc ID
residue_starts = get_residue_starts(atoms, add_exclusive_stop=True)
for start, stop in zip(residue_starts[:-1], residue_starts[1:]):
letter_altloc_ids = [loc for loc in altloc_ids[start:stop] if loc.isalpha()]
letter_altloc_ids = [loc for loc in altloc_ids[start:stop] if loc.isalnum()]
if len(letter_altloc_ids) > 0:
first_id = letter_altloc_ids[0]
altloc_filter[start:stop] |= altloc_ids[start:stop] == first_id
Expand Down Expand Up @@ -603,7 +603,7 @@ def filter_highest_occupancy_altloc(atoms, altloc_ids, occupancies):
occupancies_in_res = occupancies[start:stop]
altloc_ids_in_res = altloc_ids[start:stop]

letter_altloc_ids = [loc for loc in altloc_ids_in_res if loc.isalpha()]
letter_altloc_ids = [loc for loc in altloc_ids_in_res if loc.isalnum()]

if len(letter_altloc_ids) > 0:
highest = -1.0
Expand Down
2 changes: 1 addition & 1 deletion src/rust/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn add_subpackage(
) -> PyResult<()> {
module.add_submodule(submodule)?;
let sys = PyModule::import(module.py(), "sys")?;
let sys_modules: Bound<'_, PyDict> = sys.getattr("modules")?.downcast_into()?;
let sys_modules: Bound<'_, PyDict> = sys.getattr("modules")?.cast_into()?;
submodule.setattr("__name__", submodule_name)?;
submodule.setattr("__package__", submodule_name)?;
sys_modules.set_item(submodule_name, submodule)?;
Expand Down
2 changes: 1 addition & 1 deletion src/rust/structure/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use pyo3::prelude::*;
mod pdb;

pub fn module<'py>(parent_module: &Bound<'py, PyModule>) -> PyResult<Bound<'py, PyModule>> {
let module = PyModule::new(parent_module.py(), "structure")?;
let module = PyModule::new(parent_module.py(), "io")?;
add_subpackage(
&module,
&pdb::module(&module)?,
Expand Down
9 changes: 5 additions & 4 deletions src/rust/structure/io/pdb/file.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Low-level PDB file parsing and writing.

use ndarray::Axis;
use num_traits::{Float, FloatConst};
use numpy::ndarray::Axis;
use numpy::ndarray::{
Array, Array1, Array2, ArrayView1, ArrayView3, ArrayViewD, ArrayViewMut1, Ix3,
};
Expand Down Expand Up @@ -109,7 +109,7 @@ impl PDBFile {
#[classmethod]
fn read<'py>(cls: &Bound<'py, PyType>, file: Bound<'py, PyAny>) -> PyResult<Bound<'py, PyAny>> {
let contents;
if let Ok(file_path) = file.downcast::<PyString>() {
if let Ok(file_path) = file.cast::<PyString>() {
// String path
contents = fs::read_to_string(file_path.extract::<String>()?).map_err(|_| {
exceptions::PyOSError::new_err(format!("'{}' cannot be read", file_path))
Expand All @@ -135,7 +135,7 @@ impl PDBFile {

fn write(&self, file: Bound<'_, PyAny>) -> PyResult<()> {
let content = self.lines.join("\n");
if let Ok(file_path) = file.downcast::<PyString>() {
if let Ok(file_path) = file.cast::<PyString>() {
// String path
fs::write(file_path.extract::<String>()?, content).map_err(|_| {
exceptions::PyOSError::new_err(format!("'{}' cannot be written", file_path))
Expand Down Expand Up @@ -1177,7 +1177,8 @@ fn get_annotation_as_type<'py, T: numpy::Element>(
atoms
.getattr(annotation)?
.call_method("astype", (), Some(&kwargs))?
.extract()
.cast_into()
.map_err(|e| e.into())
}

// Get an `AtomArray` annotation as a `Vec` of strings.
Expand Down
2 changes: 1 addition & 1 deletion src/rust/structure/io/pdb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use file::*;
use hybrid36::*;

pub fn module<'py>(parent_module: &Bound<'py, PyModule>) -> PyResult<Bound<'py, PyModule>> {
let module = PyModule::new(parent_module.py(), "structure")?;
let module = PyModule::new(parent_module.py(), "pdb")?;
module.add_class::<PDBFile>()?;
module.add_function(wrap_pyfunction!(encode_hybrid36, &module)?)?;
module.add_function(wrap_pyfunction!(decode_hybrid36, &module)?)?;
Expand Down
3 changes: 1 addition & 2 deletions tests/database/test_rcsb.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,7 @@ def test_search_content_types():
("2VB1_1",),
("7VOS_1", "3A38_1", "5D8V_1"),
("1UCS_1",),
("3NIR_1", "1EJG_1"),
("9EWK_1",),
("3NIR_1", "9EWK_1", "1EJG_1"),
]
),
),
Expand Down
Binary file added tests/structure/data/1k6p.bcif
Binary file not shown.
Loading
Loading