Skip to content

Commit 97e82f2

Browse files
committed
Add graph-based model interfaces for toolkit abstraction
New model/ package with 5 toolkit-agnostic interfaces: - AtomNode: graph node representing an atom - BondEdge: graph edge representing a bond - MolecularGraph: labeled molecular graph (nodes + edges) - ReactionGraph: reaction as graph transformation - ChemToolkit: adapter interface + global registry Zero CDK imports in model/ package. Users can implement these for CDK, RDKit-via-JNI, OpenBabel, or any chemistry toolkit. Co-Authored-By: Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>
1 parent c23cdda commit 97e82f2

5 files changed

Lines changed: 329 additions & 0 deletions

File tree

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (C) 2007-2026 Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301 USA
18+
*/
19+
package com.bioinceptionlabs.reactionblast.model;
20+
21+
/**
22+
* Graph node representing an atom. Toolkit-agnostic — implementations
23+
* wrap CDK IAtom, RDKit Atom, OpenBabel OBAtom, etc.
24+
*
25+
* @author Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>
26+
*/
27+
public interface AtomNode {
28+
29+
String getSymbol();
30+
31+
int getAtomicNumber();
32+
33+
Integer getFormalCharge();
34+
35+
Integer getMassNumber();
36+
37+
boolean isAromatic();
38+
39+
void setAromatic(boolean aromatic);
40+
41+
Integer getImplicitHydrogenCount();
42+
43+
String getId();
44+
45+
void setId(String id);
46+
47+
Object getProperty(String key);
48+
49+
void setProperty(String key, Object value);
50+
51+
boolean getFlag(int flag);
52+
53+
void setFlag(int flag, boolean value);
54+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (C) 2007-2026 Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301 USA
18+
*/
19+
package com.bioinceptionlabs.reactionblast.model;
20+
21+
/**
22+
* Graph edge representing a chemical bond. Toolkit-agnostic — implementations
23+
* wrap CDK IBond, RDKit Bond, OpenBabel OBBond, etc.
24+
*
25+
* @author Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>
26+
*/
27+
public interface BondEdge {
28+
29+
AtomNode getSource();
30+
31+
AtomNode getTarget();
32+
33+
BondOrder getOrder();
34+
35+
void setOrder(BondOrder order);
36+
37+
boolean isAromatic();
38+
39+
void setAromatic(boolean aromatic);
40+
41+
boolean connects(AtomNode atom);
42+
43+
enum BondOrder {
44+
SINGLE(1), DOUBLE(2), TRIPLE(3), QUADRUPLE(4), UNSET(0);
45+
46+
private final int numeric;
47+
48+
BondOrder(int numeric) {
49+
this.numeric = numeric;
50+
}
51+
52+
public int numeric() {
53+
return numeric;
54+
}
55+
}
56+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/*
2+
* Copyright (C) 2007-2026 Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301 USA
18+
*/
19+
package com.bioinceptionlabs.reactionblast.model;
20+
21+
import java.util.Map;
22+
23+
/**
24+
* Toolkit adapter interface + global registry.
25+
* Implement this for CDK, RDKit, OpenBabel, etc.
26+
*
27+
* Usage:
28+
* <pre>
29+
* ChemToolkit.register(new CDKToolkit()); // once at startup
30+
* ReactionGraph rxn = ChemToolkit.get().parseReactionSmiles("CC>>CC");
31+
* </pre>
32+
*
33+
* @author Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>
34+
*/
35+
public interface ChemToolkit {
36+
37+
// ---- Parsing ----
38+
39+
ReactionGraph parseReactionSmiles(String smiles);
40+
41+
MolecularGraph parseMoleculeSmiles(String smiles);
42+
43+
// ---- Serialization ----
44+
45+
String toSmiles(MolecularGraph mol);
46+
47+
String toSmiles(ReactionGraph rxn);
48+
49+
String toCanonicalSmiles(MolecularGraph mol);
50+
51+
// ---- Perception ----
52+
53+
void perceiveAtomTypes(MolecularGraph mol);
54+
55+
void perceiveAromaticity(MolecularGraph mol);
56+
57+
void addImplicitHydrogens(MolecularGraph mol);
58+
59+
// ---- Substructure / MCS ----
60+
61+
boolean isSubstructure(MolecularGraph query, MolecularGraph target);
62+
63+
Map<AtomNode, AtomNode> findMCS(MolecularGraph mol1, MolecularGraph mol2);
64+
65+
// ---- Factory methods ----
66+
67+
MolecularGraph createMolecularGraph();
68+
69+
AtomNode createAtomNode(String symbol);
70+
71+
BondEdge createBondEdge(AtomNode source, AtomNode target, BondEdge.BondOrder order);
72+
73+
ReactionGraph createReactionGraph();
74+
75+
// ---- Global registry ----
76+
77+
static ChemToolkit get() {
78+
return ChemToolkitRegistry.INSTANCE;
79+
}
80+
81+
static void register(ChemToolkit toolkit) {
82+
ChemToolkitRegistry.INSTANCE = toolkit;
83+
}
84+
}
85+
86+
/**
87+
* Internal holder for the global toolkit singleton.
88+
*/
89+
class ChemToolkitRegistry {
90+
static volatile ChemToolkit INSTANCE;
91+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright (C) 2007-2026 Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301 USA
18+
*/
19+
package com.bioinceptionlabs.reactionblast.model;
20+
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
/**
25+
* Labeled molecular graph — nodes are atoms, edges are bonds.
26+
* Toolkit-agnostic — implementations wrap CDK IAtomContainer,
27+
* RDKit RWMol, OpenBabel OBMol, etc.
28+
*
29+
* @author Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>
30+
*/
31+
public interface MolecularGraph {
32+
33+
int getNodeCount();
34+
35+
int getEdgeCount();
36+
37+
AtomNode getNode(int index);
38+
39+
BondEdge getEdge(int index);
40+
41+
int indexOf(AtomNode node);
42+
43+
Iterable<AtomNode> nodes();
44+
45+
Iterable<BondEdge> edges();
46+
47+
List<BondEdge> getEdges(AtomNode node);
48+
49+
List<AtomNode> getNeighbors(AtomNode node);
50+
51+
BondEdge getEdge(AtomNode a, AtomNode b);
52+
53+
String getId();
54+
55+
void setId(String id);
56+
57+
Object getProperty(String key);
58+
59+
void setProperty(String key, Object value);
60+
61+
MolecularGraph clone() throws CloneNotSupportedException;
62+
63+
void addNode(AtomNode node);
64+
65+
void addEdge(BondEdge edge);
66+
67+
void removeNode(AtomNode node);
68+
69+
void removeEdge(BondEdge edge);
70+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (C) 2007-2026 Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301 USA
18+
*/
19+
package com.bioinceptionlabs.reactionblast.model;
20+
21+
import java.util.Map;
22+
23+
/**
24+
* Reaction as a graph transformation: reactant graphs → product graphs
25+
* with atom-atom mapping between them. Toolkit-agnostic.
26+
*
27+
* @author Syed Asad Rahman <asad.rahman@bioinceptionlabs.com>
28+
*/
29+
public interface ReactionGraph {
30+
31+
int getReactantCount();
32+
33+
int getProductCount();
34+
35+
MolecularGraph getReactant(int index);
36+
37+
MolecularGraph getProduct(int index);
38+
39+
Iterable<MolecularGraph> getReactants();
40+
41+
Iterable<MolecularGraph> getProducts();
42+
43+
void addReactant(MolecularGraph mol);
44+
45+
void addProduct(MolecularGraph mol);
46+
47+
String getId();
48+
49+
void setId(String id);
50+
51+
Map<AtomNode, AtomNode> getAtomMapping();
52+
53+
void setAtomMapping(Map<AtomNode, AtomNode> mapping);
54+
55+
boolean isMapped();
56+
57+
ReactionGraph clone() throws CloneNotSupportedException;
58+
}

0 commit comments

Comments
 (0)