Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ __pycache__/
*$py.class
*.pth

# Data files
*.pt
*.npz
*.csv
*.sdf
*.gz
*.swp
downstream/datasets/*/processed/
downstream/datasets/*/raw/

# Project file
logs/
application/
Expand Down
826 changes: 420 additions & 406 deletions EDG/config_distillation.py

Large diffs are not rendered by default.

100 changes: 50 additions & 50 deletions EDG/data_utils.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,50 @@
import collections.abc as container_abcs

import numpy as np
import torch
from torch.utils.data.dataloader import default_collate
from torch_geometric.data import Data, Batch

string_classes, int_classes = str, int


class DualCollater(object):
def __init__(self, follow_batch, multigpu=False):
self.follow_batch = follow_batch
self.multigpu = multigpu

def collate(self, batch):

elem = batch[0]
if isinstance(elem, Data):
if self.multigpu:
return batch
else:
batch = Batch.from_data_list(batch, self.follow_batch)
if "img_feat" in batch:
# assert len(batch.img_feat.shape) == 1 # img_feat 被拉平了
# n = batch.num_graphs
batch.img_feat = torch.from_numpy(np.stack(batch.img_feat))
# batch.img_feat = batch.img_feat.resize(n, 512)
return batch
elif isinstance(elem, torch.Tensor):
return default_collate(batch)
elif isinstance(elem, np.ndarray):
return default_collate(batch)
elif isinstance(elem, float):
return torch.tensor(batch, dtype=torch.float)
elif isinstance(elem, int_classes):
return torch.tensor(batch)
elif isinstance(elem, string_classes):
return batch
elif isinstance(elem, container_abcs.Mapping):
return {key: self.collate([d[key] for d in batch]) for key in elem}
elif isinstance(elem, tuple) and hasattr(elem, '_fields'):
return type(elem)(*(self.collate(s) for s in zip(*batch)))
elif isinstance(elem, container_abcs.Sequence):
return [self.collate(s) for s in zip(*batch)]

raise TypeError('DataLoader found invalid type: {}'.format(type(elem)))

def __call__(self, batch):
return self.collate(batch)
import collections.abc as container_abcs
import numpy as np
import torch
from torch.utils.data.dataloader import default_collate
from torch_geometric.data import Data, Batch
string_classes, int_classes = str, int
class DualCollater(object):
def __init__(self, follow_batch, multigpu=False):
self.follow_batch = follow_batch
self.multigpu = multigpu
def collate(self, batch):
elem = batch[0]
if isinstance(elem, Data):
if self.multigpu:
return batch
else:
batch = Batch.from_data_list(batch, self.follow_batch)
if "img_feat" in batch:
# assert len(batch.img_feat.shape) == 1 # img_feat 被拉平了
# n = batch.num_graphs
batch.img_feat = torch.from_numpy(np.stack(batch.img_feat))
# batch.img_feat = batch.img_feat.resize(n, 512)
return batch
elif isinstance(elem, torch.Tensor):
return default_collate(batch)
elif isinstance(elem, np.ndarray):
return default_collate(batch)
elif isinstance(elem, float):
return torch.tensor(batch, dtype=torch.float)
elif isinstance(elem, int_classes):
return torch.tensor(batch)
elif isinstance(elem, string_classes):
return batch
elif isinstance(elem, container_abcs.Mapping):
return {key: self.collate([d[key] for d in batch]) for key in elem}
elif isinstance(elem, tuple) and hasattr(elem, '_fields'):
return type(elem)(*(self.collate(s) for s in zip(*batch)))
elif isinstance(elem, container_abcs.Sequence):
return [self.collate(s) for s in zip(*batch)]
raise TypeError('DataLoader found invalid type: {}'.format(type(elem)))
def __call__(self, batch):
return self.collate(batch)
30 changes: 30 additions & 0 deletions EDG/dataset/QM9/raw/QM9_README
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
QM9 is a comprehensive dataset that provides geometric, energetic, electronic and thermodynamic properties for a subset of GDB-17 database, comprising 134 thousand stable organic molecules with up to 9 heavy atoms. All moleucles are modeled using density functional theory (B3LYP/6-31G(2df,p) based DFT).

The data files:
qm9.sdf: molecular structures
qm9.sdf.csv: tables for molecular properties
"mol_id" - Molecule ID (gdb9 index) mapping to the .sdf file
"A" - Rotational constant (unit: GHz)
"B" - Rotational constant (unit: GHz)
"C" - Rotational constant (unit: GHz)
"mu" - Dipole moment (unit: D)
"alpha" - Isotropic polarizability (unit: Bohr^3)
"homo" - Highest occupied molecular orbital energy (unit: Hartree)
"lumo" - Lowest unoccupied molecular orbital energy (unit: Hartree)
"gap" - Gap between HOMO and LUMO (unit: Hartree)
"r2" - Electronic spatial extent (unit: Bohr^2)
"zpve" - Zero point vibrational energy (unit: Hartree)
"u0" - Internal energy at 0K (unit: Hartree)
"u298" - Internal energy at 298.15K (unit: Hartree)
"h298" - Enthalpy at 298.15K (unit: Hartree)
"g298" - Free energy at 298.15K (unit: Hartree)
"cv" - Heat capavity at 298.15K (unit: cal/(mol*K))
"u0_atom" - Atomization energy at 0K (unit: kcal/mol)
"u298_atom" - Atomization energy at 298.15K (unit: kcal/mol)
"h298_atom" - Atomization enthalpy at 298.15K (unit: kcal/mol)
"g298_atom" - Atomization free energy at 298.15K (unit: kcal/mol)
*"u0_atom" ~ "g298_atom" are calculated from the differences between "u0" ~ "g298" and sum of reference energies of all atoms in the molecules, as given in https://figshare.com/articles/Atomref%3A_Reference_thermochemical_energies_of_H%2C_C%2C_N%2C_O%2C_F_atoms./1057643

Reference:
Blum, Lorenz C., and Jean-Louis Reymond. "970 million druglike small molecules for virtual screening in the chemical universe database GDB-13." Journal of the American Chemical Society 131.25 (2009): 8732-8733.
Ramakrishnan, Raghunathan, et al. "Quantum chemistry structures and properties of 134 kilo molecules." Scientific data 1 (2014): 140022.
11 changes: 11 additions & 0 deletions EDG/dataset/QM9/raw/atomref.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

=========================================================================================================
Ele- ZPVE U (0 K) U (298.15 K) H (298.15 K) G (298.15 K) CV
ment Hartree Hartree Hartree Hartree Hartree Cal/(Mol Kelvin)
=========================================================================================================
H 0.000000 -0.500273 -0.498857 -0.497912 -0.510927 2.981
C 0.000000 -37.846772 -37.845355 -37.844411 -37.861317 2.981
N 0.000000 -54.583861 -54.582445 -54.581501 -54.598897 2.981
O 0.000000 -75.064579 -75.063163 -75.062219 -75.079532 2.981
F 0.000000 -99.718730 -99.717314 -99.716370 -99.733544 2.981
=========================================================================================================
Loading