Skip to content

Commit 1a9a8cf

Browse files
committed
Molecule: new method from_json for deserialize from to_json
use to_json_renderable for template rendering
1 parent 48abc68 commit 1a9a8cf

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# [[file:spdkit-python.note::e345323a][e345323a]]
22
[package]
33
name = "spdkit-python"
4-
version = "0.1.16"
4+
version = "0.2.0"
55
edition = "2021"
66
authors = ["Wenping Guo <[email protected]>"]
77
description = "structure prediction kit for python"

src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,25 @@ impl PyMolecule {
443443
Self { inner }
444444
}
445445

446+
/// Return its json representation of molecule object for template rendering.
447+
pub fn to_json_renderable(&self) -> PyResult<String> {
448+
let json = gchemol::io::to_json(&self.inner)?;
449+
Ok(json)
450+
}
451+
446452
/// Return its json representation of molecule object.
447453
pub fn to_json(&self) -> PyResult<String> {
448-
let json = gchemol::io::to_json(&self.inner)?;
454+
let json = self.inner.to_json()?;
449455
Ok(json)
450456
}
451457

458+
/// Return its json representation of molecule object.
459+
#[staticmethod]
460+
pub fn from_json(json: &str) -> PyResult<Self> {
461+
let inner = Molecule::from_json(json)?;
462+
Ok(Self { inner })
463+
}
464+
452465
/// Replace atom `i` with new `atom`.
453466
pub fn set_atom(&mut self, i: usize, atom: PyAtom) -> PyResult<()> {
454467
let a = self.inner.get_atom_mut(i).ok_or(format_err!("no atom {i}"))?;

0 commit comments

Comments
 (0)