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

BonDNet #12

Merged
merged 186 commits into from
Nov 6, 2023
Merged
Changes from 1 commit
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
4871a84
attempting to resurrect atom mapping
samblau Apr 6, 2023
6fb1d42
Merge branch 'sam_dev' into atom_mapping_2023
samblau Apr 6, 2023
350c179
new atom mapping testing
samblau Apr 7, 2023
4300e54
small tweak
samblau Apr 7, 2023
a4f07b0
Debugging old atom mapping now possible
samblau Apr 8, 2023
1aefe9b
Debugging old atom mapping
samblau Apr 10, 2023
c0e6e0d
Merge branch 'sam_dev' into atom_mapping_2023
samblau May 7, 2023
ea87b5e
Minor progress
samblau May 8, 2023
adac528
noH_graph just the start
samblau May 16, 2023
6157475
compressed graph
samblau May 23, 2023
873b2c2
mapping nearly working
samblau May 24, 2023
2f59a51
Atom mapping working (without symmetry)
samblau May 24, 2023
494ccf4
address last (?) corner case
samblau May 25, 2023
0eb3511
bug fix A+A -> AA case
samblau May 25, 2023
9d7bd1f
starting to deal with small mol symmetry
samblau May 25, 2023
095bda0
co3 dealt with?
samblau May 26, 2023
d129033
report issues
samblau May 26, 2023
65db489
fix report issues
samblau May 26, 2023
83833be
Symmetry solved?!?!
samblau Jun 3, 2023
3c8f839
Phase 1 atom mapping fixes
samblau Jun 6, 2023
c3aa765
add mapping for redox and charge transfer
samblau Jun 6, 2023
4018648
Mapping fully working for all tests!
samblau Jun 6, 2023
0d0b02d
Tiny tweak
samblau Jun 6, 2023
6a3a2e7
test_1
Jun 29, 2023
a2ad798
test_2
Jun 29, 2023
3defee5
test for creating dgl molecule graphs
Jun 29, 2023
ae02fd7
test for creating dgl molecule graphs
Jun 29, 2023
bebf00e
test
Jun 29, 2023
00e7495
test
Jun 29, 2023
de51473
bug_fix
Jun 29, 2023
0b7081b
bug_fix
Jun 29, 2023
d75bda3
bug_fix
Jun 29, 2023
372a43d
non_metal_bonds
Jun 29, 2023
a618276
normalization trial 1
Jun 29, 2023
864cd44
normalization trial 1
Jun 29, 2023
02089fd
reaction_filter_trial
Jun 29, 2023
57ae06d
reaction_filter_trial
Jun 29, 2023
f6e1f53
reaction_filter_trial
Jun 29, 2023
17f67ca
bug fix
Jun 29, 2023
a4b9d8e
bug_fix
Jun 29, 2023
2a11766
update files
Jun 29, 2023
4a60501
bug fix
Jun 29, 2023
757335d
test
Jun 29, 2023
e98d920
transform atom mapping test
Jul 6, 2023
bdb8d23
bug fix
Jul 6, 2023
a07c468
bug fix
Jul 6, 2023
ca22091
print netwrokx_graph
Jul 6, 2023
79dca7d
printing
Jul 6, 2023
292db4d
printing
Jul 6, 2023
3fb7549
printing
Jul 6, 2023
8860b3e
printing
Jul 6, 2023
914968c
check total_bonds
Jul 6, 2023
386c4a8
check total_bonds
Jul 6, 2023
7f294b8
check total_bonds
Jul 6, 2023
c44b560
check total_bonds
Jul 6, 2023
75b1c90
check total_bonds
Jul 6, 2023
b866b17
check total_bonds
Jul 6, 2023
29ac7b0
check total_bonds
Jul 6, 2023
45a482b
check total_bonds
Jul 6, 2023
3c31d62
check total_bonds
Jul 6, 2023
14422fd
print bonds broken
Jul 6, 2023
7201a50
fix assert
Jul 6, 2023
be5cc0a
bonds
Jul 6, 2023
3a9b9d1
bonds
Jul 6, 2023
f339820
bonds
Jul 6, 2023
2379a56
edge_case
Jul 6, 2023
fdeb032
edge_case
Jul 6, 2023
a4d057c
edge_case
Jul 6, 2023
6e69bed
fix
Jul 6, 2023
c0f34a9
fix
Jul 6, 2023
b652242
trial
Jul 6, 2023
049c272
trial2
Jul 6, 2023
d2000ed
fix trial2
Jul 6, 2023
4f1f43e
fix trial3
Jul 6, 2023
2ee6d90
investigate error
Jul 6, 2023
49ef7ac
investigate error
Jul 6, 2023
7fd1c71
trial
Jul 10, 2023
bf0c575
trial
Jul 10, 2023
3c3df7b
print
Jul 10, 2023
80c2470
trial
Jul 10, 2023
c3025f3
trial
Jul 10, 2023
25d48de
print rxn_grphs
Jul 10, 2023
3a66ac9
trial
Jul 10, 2023
1ca4b70
trial2
Jul 10, 2023
5af73df
trial3
Jul 10, 2023
61fd480
trial
Jul 10, 2023
e51851f
trial
Jul 10, 2023
620f144
trial
Jul 10, 2023
6e207fb
trial
Jul 10, 2023
1fe5ed2
trial
Jul 10, 2023
4eb9f8b
fix_error
Jul 10, 2023
a341e96
fix_error
Jul 10, 2023
d9f4ef9
fix_error
Jul 10, 2023
3e9040b
fix_error
Jul 10, 2023
dd467e3
fix_error
Jul 10, 2023
f8ef6f6
create json data
Jul 11, 2023
02523f5
create json data
Jul 11, 2023
d44f2eb
create json data
Jul 11, 2023
0fb60c1
cleaning up
Jul 11, 2023
bc953b7
clean codes
Jul 11, 2023
919aae4
clean codes
Jul 11, 2023
0feb99e
clean codes
Jul 11, 2023
5bc7271
clean codes
Jul 11, 2023
b96f2de
clean codes
Jul 11, 2023
47d51ed
clean codes
Jul 11, 2023
cfa7148
fix assert
Jul 11, 2023
b58ac35
clean code
Jul 11, 2023
f42a3bb
change some words
Jul 11, 2023
c4d1b67
testing
Jul 11, 2023
cc3109f
add mol_wrapper pickle
Jul 13, 2023
e6195e2
fix error
Jul 13, 2023
f482234
trial
Jul 13, 2023
44b3ee8
add
Jul 13, 2023
219d9a9
successfully grab molwrapper
Jul 20, 2023
dda7913
include lmdb
Jul 24, 2023
fad4dbe
fix error
Jul 25, 2023
bcb3371
fix error
Jul 25, 2023
ba88bab
lmdb error fix trial
Jul 25, 2023
84935bc
trial
Jul 25, 2023
7734c12
trial
Jul 25, 2023
933744f
trial
Jul 25, 2023
f94e3ea
trial
Jul 25, 2023
c1d1ce3
trial
Jul 25, 2023
d82a728
trial
Jul 25, 2023
644f2ca
trial
Jul 25, 2023
4f70212
trial
Jul 25, 2023
eca83a5
trial
Jul 25, 2023
af2468f
trial
Jul 25, 2023
d625afa
small change
Jul 25, 2023
908f043
trial
Jul 25, 2023
c7ab1a7
trial
Jul 25, 2023
228cf70
trial
Jul 25, 2023
f666ed4
trial
Jul 25, 2023
132e382
trial
Jul 25, 2023
4196bed
trial
Jul 25, 2023
dfd8958
remove printing
Jul 25, 2023
ae0aa18
remove printing
Jul 25, 2023
05ee81c
add
Jul 26, 2023
874a240
add printing
Jul 26, 2023
f4296c3
trial2
Jul 26, 2023
d25076c
trial2
Jul 26, 2023
13ee61b
trial
Jul 26, 2023
588d20f
trial2
Jul 26, 2023
1d67df6
trial2
Jul 26, 2023
ded6b04
trial3
Jul 27, 2023
5bd470d
trial3
Jul 27, 2023
42413f7
trial4
Jul 27, 2023
61d9089
time it
Jul 27, 2023
5002136
trial5
Jul 27, 2023
8992d98
trial5
Jul 27, 2023
ed69385
trial
Jul 27, 2023
fcdeb83
trial
Jul 27, 2023
c68711f
fix
Jul 27, 2023
c4bee31
trial
Jul 27, 2023
0bb71cc
print
Jul 27, 2023
59298d6
save grapher features
Jul 27, 2023
4329323
change
Jul 27, 2023
cd0a41b
fix error
Jul 27, 2023
335faa8
trial
Aug 1, 2023
c21933b
trial
Aug 1, 2023
4b503e1
trial
Aug 1, 2023
0b94533
trial
Aug 1, 2023
9779e71
trial
Aug 1, 2023
3ad4b1d
trial
Aug 1, 2023
5a1b8f8
trial
Aug 1, 2023
39fe073
trial
Aug 1, 2023
8648f14
trial
Aug 1, 2023
da2e980
trial
Aug 1, 2023
74d9ce6
trial
Aug 1, 2023
167eaf9
print
Aug 3, 2023
f3114ec
only redox
Aug 3, 2023
59321f4
printing
Aug 3, 2023
ed0f18a
printing
Aug 3, 2023
e6a4c75
printing
Aug 3, 2023
ae0aea1
check atom_map
Aug 3, 2023
6e2b418
Merge branch 'sam_dev' into BonDNet
samblau Nov 2, 2023
19b9df9
Merge branch 'sam_dev' into atom_mapping_2023
samblau Nov 2, 2023
d558563
Merge branch 'atom_mapping_2023' into BonDNet
samblau Nov 2, 2023
3bdeb29
Merge branch 'sam_dev' into atom_mapping_2023
samblau Nov 3, 2023
365ae1a
Merge branch 'atom_mapping_2023' into BonDNet
samblau Nov 3, 2023
0c7f299
Merge branch 'sam_dev' into atom_mapping_2023
samblau Nov 3, 2023
8ac73d2
Merge branch 'atom_mapping_2023' into BonDNet
samblau Nov 3, 2023
594fcd2
Merge branch 'sam_dev' into atom_mapping_2023
samblau Nov 6, 2023
cd87c92
Merge branch 'atom_mapping_2023' into BonDNet
samblau Nov 6, 2023
d4c3bc7
Merge branch 'sam_dev' into atom_mapping_2023
samblau Nov 6, 2023
64c7d40
Merge branch 'atom_mapping_2023' into BonDNet
samblau Nov 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
cleaning up
  • Loading branch information
Hyelim Yang committed Jul 11, 2023
commit 0fb60c15e3f23d2934dd1467d88e5066f77d3d92
102 changes: 69 additions & 33 deletions HiPRGen/rxn_networks_graph.py
Original file line number Diff line number Diff line change
@@ -25,20 +25,31 @@ def create_rxn_networks_graph(self, rxn, rxn_id):

# Transfrom reaction data to the following:
"""mappings = {
"bond_map": rxn.bond_mapping,
"atom_map": rxn.atom_mapping,
"total_bonds": list of list,
"bond_map": a list of lists,
e.g.) For a reaction that has two reactants and two products, it has [[{}, {}], [{}, {}]] format.
The first inner list includes dictionaries of bond map for reactants.
The second inner list includes dictionaries of bond map for products.
A key of the dictionary represents a local bond index and the corresponding value represents
a global bond index from "total_bonds".
"atom_map": a list of lists,
e.g.) For a reaction that has two reactants and two products, it has [[{}, {}], [{}, {}]] format.
The first inner list includes dictionaries of atom map for reactants.
The second inner list includes dictionaries of atom map for products.
A key of the dictionary represetns a local atom index and the corresponding value represents
a global atom index.
"total_bonds": list of lists whose length is 2. It's an union of bonds in reactants and products
e.g.) [[0,1], [0,2], [0,3], [0, 4]]
"total_atoms": list of integer,
"num_bonds_total": integer == len(total_bonds),
"num_atoms_total": integer == len(total_atoms),
}"""


atom_map = rxn['atom_map']
transformed_atom_map = []
num_reactants = rxn['number_of_reactants']
num_products = rxn['number_of_products']
reactants_entry_ids = []
transformed_atom_map = []

products_entry_ids = []

# step 1: Transform atom mapping
@@ -67,31 +78,55 @@ def create_rxn_networks_graph(self, rxn, rxn_id):
assert sum([len(i) for i in reactants]) == sum([len(i) for i in products])
assert num_reactants == len(reactants)
assert num_products == len(products)

# Get "total_atoms"
num_tot_atoms = sum([len(i) for i in reactants])
total_atoms = [i for i in range(num_tot_atoms)]


# step 2: Get total_bonds which is a union of bonds in reactants and products
reactants_total_bonds = set()
for k, ind in enumerate(rxn['reactants']):
mol_reactant = self.mol_entries[ind]
networkx_graph = mol_reactant.graph
if len(reactants) <= k: # list index out of range
break
reactants_entry_ids.append(self.mol_entries[ind].entry_id)
for i, j, weight in networkx_graph.edges:
reactants_total_bonds.add(tuple(sorted([reactants[k][i], reactants[k][j]])))
def find_total_bonds(rxn, species, reactants, products):
species_entry_ids = []
species_total_bonds = set()
if species == 'reactants':
temp_species = reactants
else:
temp_species = products
for k, ind in enumerate(rxn[species]):
mol_reactant = self.mol_entries[ind]
networkx_graph = mol_reactant.graph
# This is needed because there is a case where num_reactants != len(rxn['reactants']) or num_products != len(rxn['products'])
if len(temp_species) <= k:
break
species_entry_ids.append(self.mol_entries[ind].entry_id)
for i, j, weight in networkx_graph.edges:
species_total_bonds.add(tuple(sorted([temp_species[k][i], temp_species[k][j]])))
return species_total_bonds, species_entry_ids

reactants_total_bonds, reactants_entry_ids = find_total_bonds(rxn, 'reactants', reactants, products)
products_total_bonds, products_entry_ids = find_total_bonds(rxn, 'products', reactants, products)

# reactants_total_bonds = set()
# for k, ind in enumerate(rxn['reactants']):
# mol_reactant = self.mol_entries[ind]
# networkx_graph = mol_reactant.graph
# # This is needed because there is a case where num_reactants != len(rxn['reactants'])
# if len(reactants) <= k:
# break
# reactants_entry_ids.append(self.mol_entries[ind].entry_id)
# for i, j, weight in networkx_graph.edges:
# reactants_total_bonds.add(tuple(sorted([reactants[k][i], reactants[k][j]])))


products_total_bonds = set()
for k, ind in enumerate(rxn['products']):
mol_reactant = self.mol_entries[ind]
networkx_graph = mol_reactant.graph
if len(products) <= k: # list index out of range
break
products_entry_ids.append(self.mol_entries[ind].entry_id)
for i, j, weight in networkx_graph.edges:
products_total_bonds.add(tuple(sorted([products[k][i], products[k][j]])))
# products_total_bonds = set()
# for k, ind in enumerate(rxn['products']):
# mol_reactant = self.mol_entries[ind]
# networkx_graph = mol_reactant.graph
# if len(products) <= k: # list index out of range
# break
# products_entry_ids.append(self.mol_entries[ind].entry_id)
# for i, j, weight in networkx_graph.edges:
# products_total_bonds.add(tuple(sorted([products[k][i], products[k][j]])))

set_total_bonds = reactants_total_bonds.union(products_total_bonds)
total_bonds = [[i,j] for i, j in set_total_bonds]
@@ -139,14 +174,14 @@ def create_rxn_networks_graph(self, rxn, rxn_id):
mappings['num_atoms_total'] = len(total_atoms)

#print(f"mapping: {mappings}")
print(f"atom_map: {atom_map}")
print(f"reactants: {reactants}")
print(f"products: {products}")
# print(f"atom_map: {atom_map}")
# print(f"reactants: {reactants}")
# print(f"products: {products}")
# step 5: Create a reaction graphs and features
reactants_dgl_graphs = [self.dgl_mol_dict[entry_i] for entry_i in reactants_entry_ids]
print(f"reactants_dgl_graphs: {reactants_dgl_graphs}")
# print(f"reactants_dgl_graphs: {reactants_dgl_graphs}")
products_dgl_graphs = [self.dgl_mol_dict[entry_i] for entry_i in products_entry_ids]
print(f"products_dgl_graphs: {products_dgl_graphs}")
# print(f"products_dgl_graphs: {products_dgl_graphs}")

# create has_bonds
# "has_bonds" is required input to create a reaction graph from BonDNet
@@ -157,8 +192,8 @@ def create_rxn_networks_graph(self, rxn, rxn_id):
for _ in range(len(products)):
has_bonds['products'].append(True)

print(f"has_bonds: {has_bonds}")
print(f"mappings: {mappings}")
# print(f"has_bonds: {has_bonds}")
# print(f"mappings: {mappings}")
rxn_graph, features = create_rxn_graph(
reactants = reactants_dgl_graphs,
products = products_dgl_graphs,
@@ -170,17 +205,18 @@ def create_rxn_networks_graph(self, rxn, rxn_id):
reverse=False,
)

print(f"rxn_graph: {rxn_graph}")
#print(f"rxn_graph: {rxn_graph}")
# print(f"features: {features}")

# step 5: update reaction features to the reaction graph
for nt, ft in features.items():
rxn_graph.nodes[nt].data.update({'ft': ft})

self.data[rxn_id] = {}
self.data[rxn_id]['rxn_graph'] = rxn_graph
self.data[rxn_id]['value'] = torch.tensor([rxn['dG']])
self.data[rxn_id]['rxn_graph'] = str(rxn_graph)
self.data[rxn_id]['value'] = str(torch.tensor([rxn['dG']]))



def save_data(self):
#self.f.write(json.dumps(self.data))