rdkit_chem 2025.09.3.6 → 2025.09.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Code/RubyWrappers/MolOps.i +6 -9
- data/Code/RubyWrappers/ROMol.i +12 -16
- data/Code/RubyWrappers/RWMol.i +0 -21
- data/ext/rdkit_chem/extconf.rb +8 -8
- data/lib/rdkit_chem/version.rb +2 -4
- data/test/test_rdkit_chem.rb +12 -27
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f1150cd8a25cb6e75a9a1801e0377f52c7ccdc1753610fd2b60112ef43aa82b2
|
|
4
|
+
data.tar.gz: a6dd2d9705f577cec79ac17c5fe6868af3c94e90796f8f1b7f312f82ee556c08
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9483ef51984ee11ce8a6de70a46c04627e43a316313d2156ad1ddfd3973fd26b8d744ef2c48a8ad32410f3e5512f065f40aaa39d53e00b3f7e26ea5fa97d4592
|
|
7
|
+
data.tar.gz: 27318bc6b7ef5563aec63ea65248fec1b5c6c29328dc0995dde486a764002912f3f5f27573dad7c61f95edfbc3858e3ddca72be0a8c7d42e2d1cebe3633c7cc1
|
data/Code/RubyWrappers/MolOps.i
CHANGED
|
@@ -44,27 +44,24 @@
|
|
|
44
44
|
%newobject RDKit::MolOps::mergeQueryHs;
|
|
45
45
|
%newobject RDKit::MolOps::adjustQueryProperties;
|
|
46
46
|
|
|
47
|
-
// IMPORTANT: %ignore must come BEFORE %include
|
|
48
|
-
// Ignore all sanitizeMol overloads - we provide custom wrapper below
|
|
49
|
-
%ignore RDKit::MolOps::sanitizeMol;
|
|
50
47
|
%ignore RDKit::MolOps::detectChemistryProblems;
|
|
51
48
|
%include <GraphMol/MolOps.h>
|
|
49
|
+
// Ignore only the 3-arg overload that uses reference parameters (incompatible with SWIG)
|
|
50
|
+
// This keeps the 1-arg sanitizeMol(RWMol &) available from the header
|
|
51
|
+
%ignore RDKit::MolOps::sanitizeMol(RWMol &,unsigned int &,unsigned int &);
|
|
52
52
|
%template(BoolPair) std::pair<bool, bool>;
|
|
53
53
|
|
|
54
54
|
%inline %{
|
|
55
|
-
|
|
56
|
-
// Only ONE definition needed - default parameter handles both use cases
|
|
57
|
-
int sanitizeMol(RDKit::RWMol &mol, int sanitizeOps=RDKit::MolOps::SANITIZE_ALL){
|
|
55
|
+
int sanitizeMol(RDKit::RWMol &mol,int sanitizeOps){
|
|
58
56
|
unsigned int opThatFailed;
|
|
59
57
|
try{
|
|
60
|
-
RDKit::MolOps::sanitizeMol(mol,
|
|
58
|
+
RDKit::MolOps::sanitizeMol(mol,opThatFailed,
|
|
61
59
|
static_cast<unsigned int>(sanitizeOps));
|
|
62
60
|
} catch(...) {
|
|
63
61
|
|
|
64
62
|
}
|
|
65
63
|
return static_cast<int>(opThatFailed);
|
|
66
|
-
}
|
|
67
|
-
|
|
64
|
+
};
|
|
68
65
|
std::vector<boost::shared_ptr<RDKit::MolSanitizeException>> detectChemistryProblems(RDKit::ROMol &mol,int sanitizeOps=RDKit::MolOps::SANITIZE_ALL){
|
|
69
66
|
std::vector<boost::shared_ptr<RDKit::MolSanitizeException>> res;
|
|
70
67
|
auto probs = RDKit::MolOps::detectChemistryProblems(mol,sanitizeOps);
|
data/Code/RubyWrappers/ROMol.i
CHANGED
|
@@ -101,11 +101,12 @@
|
|
|
101
101
|
|
|
102
102
|
/*
|
|
103
103
|
* Special handling for Conformer objects which should not be GCed until the molecule is destroyed
|
|
104
|
-
* We
|
|
105
|
-
* to
|
|
106
|
-
*
|
|
104
|
+
* We want to modify the behavior of the Conformer coming into the addConformer method without
|
|
105
|
+
* impacting Conformer objects that are arguments to other methods. Therefore we define a pattern
|
|
106
|
+
* that will trigger special handling of the Conformer input (the addConf method match this pattern).
|
|
107
107
|
*/
|
|
108
|
-
%ignore
|
|
108
|
+
%ignore addConformer(Conformer * conf, bool assignId=false);
|
|
109
|
+
%rename(addConformer) RDKit::ROMol::addConf;
|
|
109
110
|
%include <GraphMol/ROMol.h>
|
|
110
111
|
|
|
111
112
|
%ignore SubstructMatch;
|
|
@@ -188,19 +189,14 @@ unsigned int getDefaultPickleProperties();
|
|
|
188
189
|
return res;
|
|
189
190
|
}
|
|
190
191
|
|
|
191
|
-
/*
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
return self->addConformer(
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
// Alias for addConf - exposes as add_conformer in Ruby
|
|
200
|
-
unsigned int addConformer(RDKit::Conformer *conf, bool assignId=false) {
|
|
201
|
-
RDKit::Conformer *confCopy = new RDKit::Conformer(*conf);
|
|
202
|
-
return self->addConformer(confCopy, assignId);
|
|
192
|
+
/* DISOWN directive: tells SWIG that ownership of the Conformer transfers to C++.
|
|
193
|
+
Without this, Ruby GC and C++ destructor both try to free the Conformer,
|
|
194
|
+
causing a double-free segfault at script exit. */
|
|
195
|
+
%apply SWIGTYPE *DISOWN {RDKit::Conformer *ownedConf};
|
|
196
|
+
unsigned int RDKit::ROMol::addConf(RDKit::Conformer * ownedConf, bool assignId=false) {
|
|
197
|
+
return self->addConformer(ownedConf, assignId);
|
|
203
198
|
}
|
|
199
|
+
%clear RDKit::Conformer *ownedConf;
|
|
204
200
|
|
|
205
201
|
std::string MolToSmiles(bool doIsomericSmiles=true, bool doKekule=false, int rootedAtAtom=-1, bool canonical=true,
|
|
206
202
|
bool allBondsExplicit=false, bool allHsExplicit=false, bool doRandom=false) {
|
data/Code/RubyWrappers/RWMol.i
CHANGED
|
@@ -44,13 +44,6 @@
|
|
|
44
44
|
|
|
45
45
|
%template(RWMol_Vect) std::vector< boost::shared_ptr<RDKit::RWMol> >;
|
|
46
46
|
|
|
47
|
-
/*
|
|
48
|
-
* Special handling for Conformer objects which should not be GCed until the molecule is destroyed
|
|
49
|
-
* We ignore the original addConformer and provide our own in %extend that copies the conformer
|
|
50
|
-
* to avoid double-free issues with shared_ptr wrappers.
|
|
51
|
-
*/
|
|
52
|
-
%ignore RDKit::RWMol::addConformer;
|
|
53
|
-
|
|
54
47
|
// ignore the methods that allow the molecule to take ownership of atoms/Bonds
|
|
55
48
|
// (instead of copying them). This just leads to memory problems with Ruby
|
|
56
49
|
%ignore RDKit::RWMol::addAtom(Atom *atom,bool updateLabel,bool takeOwnership);
|
|
@@ -85,20 +78,6 @@
|
|
|
85
78
|
%include <GraphMol/RWMol.h>
|
|
86
79
|
|
|
87
80
|
%extend RDKit::RWMol {
|
|
88
|
-
/* Create a copy of the conformer before adding it to the molecule.
|
|
89
|
-
This avoids the double-free issue since Ruby owns the original and C++ owns the copy.
|
|
90
|
-
The original DISOWN approach doesn't work with shared_ptr wrappers. */
|
|
91
|
-
unsigned int addConf(RDKit::Conformer *conf, bool assignId=false) {
|
|
92
|
-
RDKit::Conformer *confCopy = new RDKit::Conformer(*conf);
|
|
93
|
-
return self->addConformer(confCopy, assignId);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Alias for addConf - exposes as add_conformer in Ruby
|
|
97
|
-
unsigned int addConformer(RDKit::Conformer *conf, bool assignId=false) {
|
|
98
|
-
RDKit::Conformer *confCopy = new RDKit::Conformer(*conf);
|
|
99
|
-
return self->addConformer(confCopy, assignId);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
81
|
static RDKit::RWMOL_SPTR MolFromSmiles(const std::string &smi,int debugParse=0,bool sanitize=1,
|
|
103
82
|
std::map<std::string,std::string> *replacements=0){
|
|
104
83
|
return RDKit::RWMOL_SPTR(RDKit::SmilesToMol(smi, debugParse, sanitize,replacements));
|
data/ext/rdkit_chem/extconf.rb
CHANGED
|
@@ -16,13 +16,13 @@ rescue StandardError
|
|
|
16
16
|
nr_processors = 1
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
FileUtils.mkdir_p rdkit_dir
|
|
20
|
+
Dir.chdir main_dir do
|
|
21
|
+
FileUtils.rm_rf src_dir
|
|
22
|
+
puts 'Downloading RDKit sources'
|
|
23
|
+
git = 'git clone https://github.com/rdkit/rdkit.git'
|
|
24
|
+
system git
|
|
25
|
+
end
|
|
26
26
|
|
|
27
27
|
Dir.chdir(src_dir) do
|
|
28
28
|
checkout = 'git checkout c2e48f41d88ddc15c6e1f818d1c4ced70b7f20d1'
|
|
@@ -74,7 +74,7 @@ Dir.chdir build_dir do
|
|
|
74
74
|
end
|
|
75
75
|
|
|
76
76
|
# Remove compiled file, free spaces
|
|
77
|
-
|
|
77
|
+
FileUtils.remove_dir(rdkit_dir)
|
|
78
78
|
|
|
79
79
|
# create a fake Makefile
|
|
80
80
|
File.open(File.join(File.dirname(__FILE__), 'Makefile'), 'w+') do |makefile|
|
data/lib/rdkit_chem/version.rb
CHANGED
data/test/test_rdkit_chem.rb
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'test/unit'
|
|
2
2
|
|
|
3
|
-
require
|
|
3
|
+
require 'rdkit_chem'
|
|
4
4
|
|
|
5
5
|
class RDKitTest < Test::Unit::TestCase
|
|
6
6
|
def test_mol_from_smiles
|
|
7
|
-
smiles =
|
|
7
|
+
smiles = 'CCO' # ethanol
|
|
8
8
|
rw_mol = RDKitChem::RWMol.mol_from_smiles(smiles)
|
|
9
9
|
assert_not_nil(rw_mol)
|
|
10
10
|
assert_equal(3, rw_mol.get_num_atoms)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
def test_mol_to_mol_block
|
|
14
|
-
smiles =
|
|
14
|
+
smiles = 'CCO' # ethanol
|
|
15
15
|
rw_mol = RDKitChem::RWMol.mol_from_smiles(smiles)
|
|
16
16
|
mdl = rw_mol.mol_to_mol_block(true, -1, false)
|
|
17
17
|
assert_not_nil(mdl)
|
|
18
|
-
assert(mdl.include?(
|
|
18
|
+
assert(mdl.include?('V2000') || mdl.include?('V3000'))
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
def test_mol_from_mol_block
|
|
22
|
-
smiles =
|
|
22
|
+
smiles = 'c1ccccc1' # benzene
|
|
23
23
|
rw_mol = RDKitChem::RWMol.mol_from_smiles(smiles)
|
|
24
24
|
mdl = rw_mol.mol_to_mol_block(true, -1, false)
|
|
25
25
|
|
|
@@ -30,41 +30,26 @@ class RDKitTest < Test::Unit::TestCase
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def test_mol_to_smiles
|
|
33
|
-
smiles =
|
|
33
|
+
smiles = 'CCO'
|
|
34
34
|
rw_mol = RDKitChem::RWMol.mol_from_smiles(smiles)
|
|
35
35
|
output_smiles = RDKitChem.mol_to_smiles(rw_mol)
|
|
36
36
|
assert_not_nil(output_smiles)
|
|
37
|
-
assert_equal(
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def test_sanitize_mol
|
|
41
|
-
smiles = "c1ccccc1" # benzene
|
|
42
|
-
rw_mol = RDKitChem::RWMol.mol_from_smiles(smiles)
|
|
43
|
-
|
|
44
|
-
# sanitize_mol returns an integer (0 for success usually, or bitmask of operations failed)
|
|
45
|
-
# It might return different things based on SWIG wrapping details observed in MolOps.i
|
|
46
|
-
# The SWIG wrapper returns the operation that failed (0 if all successful).
|
|
47
|
-
result = RDKitChem.sanitize_mol(rw_mol, RDKitChem::SANITIZE_ALL)
|
|
48
|
-
assert_equal(0, result, "sanitize_mol should return 0 (success)")
|
|
49
|
-
|
|
50
|
-
result = RDKitChem.sanitize_mol(rw_mol)
|
|
51
|
-
assert_equal(0, result, "sanitize_mol should return 0 (success)")
|
|
37
|
+
assert_equal('CCO', output_smiles)
|
|
52
38
|
end
|
|
53
39
|
|
|
54
40
|
def test_cholesterol
|
|
55
41
|
# Cholesterol without chirality
|
|
56
|
-
smiles =
|
|
42
|
+
smiles = 'CC(C)CCCC(C)C1CCC2C1(CCC3C2CC=C4C3(CCC(C4)O)C)C'
|
|
57
43
|
rw_mol = RDKitChem::RWMol.mol_from_smiles(smiles)
|
|
58
44
|
assert_not_nil(rw_mol)
|
|
59
|
-
assert_equal(28, rw_mol.get_num_atoms)
|
|
45
|
+
assert_equal(28, rw_mol.get_num_atoms) # C27H46O has 28 heavy atoms (27 C + 1 O)
|
|
60
46
|
end
|
|
61
47
|
|
|
62
48
|
def test_conformer_ownership
|
|
63
|
-
# FIXME: This test causes a segfault (exit code 139) likely due to GC/double-free issues.
|
|
64
49
|
# Test that conformer ownership is properly transferred to the molecule.
|
|
65
50
|
# This verifies the DISOWN directive works - without it, Ruby GC and C++
|
|
66
51
|
# destructor both try to free the Conformer, causing a double-free segfault.
|
|
67
|
-
smiles =
|
|
52
|
+
smiles = 'CCO' # ethanol
|
|
68
53
|
rw_mol = RDKitChem::RWMol.mol_from_smiles(smiles)
|
|
69
54
|
|
|
70
55
|
# Create a conformer with 3D coordinates
|
|
@@ -74,7 +59,7 @@ class RDKitTest < Test::Unit::TestCase
|
|
|
74
59
|
conf.set_atom_pos(2, RDKitChem::Point3D.new(2.0, 1.0, 0.0))
|
|
75
60
|
|
|
76
61
|
# Add conformer to molecule (ownership transfers to C++)
|
|
77
|
-
conf_id = rw_mol.
|
|
62
|
+
conf_id = rw_mol.addConf(conf, true)
|
|
78
63
|
assert(conf_id >= 0, "Conformer should be added successfully")
|
|
79
64
|
|
|
80
65
|
# Verify conformer was added
|