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

Atomic and bond level features generated for DMPNN #119

Open
Rhys-McAlister opened this issue Dec 7, 2023 · 2 comments
Open

Atomic and bond level features generated for DMPNN #119

Rhys-McAlister opened this issue Dec 7, 2023 · 2 comments

Comments

@Rhys-McAlister
Copy link

Hi, when looking at the dimensions of the attributes for nodes and bonds it appears that there are 41 and 11 atomic and bond level features included in the DMPNN model. I was wondering if it were possible to include the full suite of features as in the original paper: https://pubs.acs.org/doi/full/10.1021/acs.jcim.9b00237 or as in the chemprop implementation of the model. As insight into how to do that would be appreciated.

Thanks

@thegodone
Copy link
Contributor

thegodone commented Dec 8, 2023

You have to change the definition of the features you used there are defaults values that you can change (encoder_nodes here). see custom examples

dts.set_attributes(
# Nodes
nodes=["Symbol", "TotalNumHs", "GasteigerCharge"],
encoder_nodes={
"Symbol": OneHotEncoder(["C", "N", "O"], dtype="str", add_unknown=False)
},
# Edges
edges=["BondType", "Stereo"],
encoder_edges = {
"BondType": int
},
# Graph-level
graph=["ExactMolWt", mol_feature],
additional_callbacks= {"size": graph_size_callback},
custom_transform=custum_trafo
)

@PatReis
Copy link
Collaborator

PatReis commented Dec 8, 2023

Yes, exactly. Thanks @thegodone .
You can modify the feature generated from mol objects of the SDF file with the set_attributes / read_in_memory method.
The default looks like this:

data.set_attributes(
    nodes = [
        'Symbol', 'TotalDegree', 'FormalCharge', 'NumRadicalElectrons', 'Hybridization',
        'IsAromatic', 'IsInRing', 'TotalNumHs', 'CIPCode', "ChiralityPossible", "ChiralTag"
    ],
    encoder_nodes = {
        'Symbol': OneHotEncoder(
            ['B', 'C', 'N', 'O', 'F', 'Si', 'P', 'S', 'Cl', 'As', 'Se', 'Br', 'Te', 'I', 'At'],
            dtype="str"
        ),
        'Hybridization': OneHotEncoder([2, 3, 4, 5, 6]),
        'TotalDegree': OneHotEncoder([0, 1, 2, 3, 4, 5], add_unknown=False),
        'TotalNumHs': OneHotEncoder([0, 1, 2, 3, 4], add_unknown=False),
        'CIPCode': OneHotEncoder(['R', 'S'], add_unknown=False, dtype='str'),
        "ChiralityPossible": OneHotEncoder(["1"], add_unknown=False, dtype='str'),
    },
    edges = ['BondType', 'IsAromatic', 'IsConjugated', 'IsInRing', 'Stereo'],
    encoder_edges = {
        'BondType': OneHotEncoder([1, 2, 3, 12], add_unknown=False),
        'Stereo': OneHotEncoder([0, 1, 2, 3], add_unknown=False)
    },
    graph=['ExactMolWt', 'NumAtoms'],
    encoder_graph = {},
    add_hydrogen=False,
    make_directed=False,
    has_conformers=True,
    sanitize=True,
    compute_partial_charges=None,
    label_column_name="measured log solubility in mols per litre"
)

The reason why it is smaller than with DMPNN paper is that we do not allow all atoms, since you would not have them
in organic molecules anyway. If you want you can add all species in the OneHotEncoder of symbol.
Also you can look here:
https://github.com/aimat-lab/gcnn_keras/blob/master/notebooks/tutorial_custom_moleculenet.ipynb
or here:
https://kgcnn.readthedocs.io/en/latest/molecules.html
to see which other features you can add. Note that you can always add your own functions in place of named attributes or custom callbacks that make entirely new arrays apart from e.g. 'node_attributes'.
If you have a certain feature in mind, let me know. I can also add this to MolecularGraphRDKit (the interface used by MoleculeNetDataset )

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

No branches or pull requests

3 participants