Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored PeriodicTable #42

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

mvisani
Copy link
Contributor

@mvisani mvisani commented Oct 10, 2024

Solves #39.

As you can see, there is no need to write the C++ function anymore. This still compiles. We would then need to write in the wrapper the constructors for our different objects and the function that cause problems in the conversion.

@xrl
Copy link
Contributor

xrl commented Oct 10, 2024

It is nice that you can just go straight to the foreign symbols! Very clean.

My main concern is the non-rusty capitalization. I take it there's no serde renaming equivalent of #[serde(rename_all = "camelCase")]? I'll think on it but this might be the move to remove the mountains of boilerplate.

@mvisani
Copy link
Contributor Author

mvisani commented Oct 11, 2024

I am not aware of such conversion but it is true that if it is "only" that, I would like to argue that we are better just keeping the camel case in order to avoid all those boilerplate.

Also, if we go in this direction, I think that the rdkit crate will not be needed anymore. Indeed, this part (in rdkit crate):

use cxx::{let_cxx_string, CxxVector};

pub struct PeriodicTable {}

impl PeriodicTable {
    pub fn get_valence_list(atomic_number: u32) -> &'static CxxVector<i32> {
        rdkit_sys::periodic_table_ffi::get_valence_list(atomic_number)
    }

    pub fn get_most_common_isotope_mass(atom: &str) -> f64 {
        let_cxx_string!(atom_cxx_string = atom);
        rdkit_sys::periodic_table_ffi::get_most_common_isotope_mass(&atom_cxx_string)
    }
}

becomes redundant because we can directly call :

let_cxx_string!(atom = "C");
let periodic_table = rdkit_sys::periodic_table_ffi::get_periodic_table();
let mass = periodic_table.getMostCommonIsotopeMass(&atom);

from the rdkit-sys crate. This would remove even more boilerplate.

@xrl
Copy link
Contributor

xrl commented Oct 12, 2024

Agreed, avoiding boilerplate is worthy of the effort. It means that in the future it'll be easier to add and modify bindings (suitable for mere mortals!).

I want to keep rdkit/rdkit-sys distinctions. Overall the architecture was always intended to be:

  • rdkit-sys: complexity of build.rs, stretch goal of perhaps vendoring a compatible rdkit like rdkafka-sys or openssl-sys. following idioms is a non-goal.
  • rdkit: high-level and fully idiomatic Rust (properly capitalized functions, for example). a place to make clone() data and make lifetimes more sane. code using the rdkit crate should look like regular Rust code.

@mvisani
Copy link
Contributor Author

mvisani commented Oct 14, 2024

I see ! That makes sense. I will finish pushing stuff to this pull request and if it is ok with you, we can start refactoring a little bit. I just checked there should only be minor changes in the rdkit crate.

@mvisani
Copy link
Contributor Author

mvisani commented Oct 14, 2024

Ok now checks fail because I have added some functions that are not available in your version of rdkit in GitHub actions. Should we update the version ? Or should I just comment the functions ?

@JJ-Pineda
Copy link
Contributor

@mvisani I've updated the GitHub workflows to use the latest RDKit release. If you merge main into your branch, it should work now.

@mvisani
Copy link
Contributor Author

mvisani commented Oct 16, 2024

@JJ-Pineda Indeed all tests pass now. Thank you !

@mvisani
Copy link
Contributor Author

mvisani commented Oct 22, 2024

@xrl All tests pass, should we proceed to merge ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants