Comments (6)
@janosh the one @douweschulte posted above is a good example awesomely made by @sverhoeven.
However the way I'm using it in our new frontend is a bit different since I've ran into a few issues when trying to use the wasm lib together with the formik validation (probably because of my bad TS 😅); see a small snippet of how it ended working:
#[wasm_bindgen]
pub fn list_chains(bytes: js_sys::Uint8Array) -> JsValue {
utils::set_panic_hook();
// go from `js_sys::Uint8Array` to `pdbtbx::PDB` (omitted)
let structure = pdb::load_pdb_from_bytes(bytes);
let chains = pdb::identify_chains(structure);
serde_wasm_bindgen::to_value(&chains).unwrap()
}
pub fn identify_chains(structure: pdbtbx::PDB) -> Vec<String> {
let mut chains: Vec<String> = Vec::new();
// I know this for is not very rusty :P
for chain in structure.chains() {
chains.push(chain.id().to_string());
}
chains
}
import init, { list_chains, chains_in_contact } from "wasm-lib"; // @ts-ignore
// ...
const identifyChains = async (bytes: Uint8Array): Promise<string[]> => {
try {
await init();
let result = await list_chains(bytes);
return result;
} catch (error) {
// error handling
return [];
}
};
const readPDB = async (file: File) => {
return new Promise<void>((resolve, reject) => {
const reader = new FileReader();
reader.onload = async () => {
if (reader.result && reader.result instanceof ArrayBuffer) {
const arrayBuffer = reader.result;
const atomBuffer = keepOnlyAtomRecords(arrayBuffer);
const observedChains = await identifyChains(
new Uint8Array(atomBuffer),
);
// ######
// observedChains is `string[]` and can be set as a state and used in the component
// ######
}
const handleFileChange = async (
event: React.ChangeEvent<HTMLInputElement>,
) => {
const file = event.target.files?.[0];
if (file) {
// ...
if (file.name.endsWith(".zip")) {
await readZIP(file);
} else if (file.name.endsWith(".pdb")) {
await readPDB(file);
}
}
};
const ProdigyForm = () => {
// ... lots of stuff here
return (
<Form>
// ...
<Field // from Formik
onChange={(e: ChangeEvent<HTMLInputElement>) => {
handleFileChange(e);
}}
In this snippet above, once a structure is uploaded in a field, the wasm lib is triggered and whatever chains are present there are returned as a string[]
. I have other functions that also calculate the contacts between the chains, rmsds and all other sort of utilities and validations, they all run very fast even in very large complexes. Hope that helps!
from pdbtbx.
I think it works best case by case, I'll draft it up as soon as I can make time.
As for if it will be useful, I certainly hope so!
Any comments @sverhoeven? I'll do this anyway for wenmr, maybe we can also add it to the ivresse projects.
from pdbtbx.
No comments, indeed using these utilities in ivresse would be nice.
from pdbtbx.
@janosh here you are: https://github.com/i-VRESSE/pdbtbx-ts. A very nice somewhat recent feature of github is that you can find forward and reverse dependencies on github itself: https://github.com/douweschulte/pdbtbx/network/dependents.
from pdbtbx.
Thanks!
In general I approve of adding any method that would have to be implemented by more than one person for their project. Feel free to open a PR with the functions you wrote and think could be useful, then we can have a discussion there about the individual functions and maybe find a way of rewriting them to be more useful in the general case. Or if you want we could also have a discussion about those here before we actually have to fit the functions into the pdbtbx
code.
from pdbtbx.
@rvhonorato sorry to hijack this thread. is your wasm lib public? i'd also like to use pdbtbx
on the frontend. interested to see how that's done
from pdbtbx.
Related Issues (20)
- Panic while parsing HOT 3
- Unable to load poor-quality PDBs HOT 6
- Allow for the use of compressed files HOT 4
- Support pdbML HOT 2
- Add SASA support HOT 14
- Panic in `save/pdb.rs:517:29` at `Option::unwrap()` on a `None` value HOT 3
- Issues with `remove_models_except` implementation HOT 2
- Crates.io new version Request HOT 1
- Bad handling of PDB files containing mixed upper and lower case chains HOT 3
- Maybe make a Discord? HOT 2
- Bad Models in PDB HOT 1
- ReadOptions
- REMARK Line Length Enforcement HOT 2
- Fall back strategy for headerless PDB files. HOT 2
- Read option to only parse `ATOM` records HOT 5
- Finish implementing the `ReadOptions`
- Customize `StrictnessLevel` HOT 9
- Refactor long functions
- Check memory footprint
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pdbtbx.