Skip to content
Open
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
29 changes: 27 additions & 2 deletions torch_geometric/datasets/qm9.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ def process(self) -> None:
if i in skip:
continue

if mol is None:
continue

N = mol.GetNumAtoms()

conf = mol.GetConformer()
Expand Down Expand Up @@ -273,6 +276,15 @@ def process(self) -> None:
rows, cols, edge_types = [], [], []
for bond in mol.GetBonds():
start, end = bond.GetBeginAtomIdx(), bond.GetEndAtomIdx()

# --- START CHANGE: Geometric Filter ---
p1 = pos[start]
p2 = pos[end]
dist = (p1 - p2).norm().item()
if dist > 1.85:
continue
# --- END CHANGE ---

rows += [start, end]
cols += [end, start]
edge_types += 2 * [bonds[bond.GetBondType()]]
Expand All @@ -288,15 +300,28 @@ def process(self) -> None:

row, col = edge_index
hs = (z == 1).to(torch.float)
num_hs = scatter(hs[row], col, dim_size=N, reduce='sum').tolist()

if row.numel() > 0:
num_hs = scatter(hs[row], col, dim_size=N,
reduce='sum').tolist()
else:
num_hs = [0.0] * N

x1 = one_hot(torch.tensor(type_idx), num_classes=len(types))
x2 = torch.tensor([atomic_number, aromatic, sp, sp2, sp3, num_hs],
dtype=torch.float).t().contiguous()
x = torch.cat([x1, x2], dim=-1)

name = mol.GetProp('_Name')
smiles = Chem.MolToSmiles(mol, isomericSmiles=True)

# --- START CHANGE: Prefer Property SMILES ---
if mol.HasProp('GDB-SMILES'):
smiles = mol.GetProp('GDB-SMILES')
elif mol.HasProp('SMILES'):
smiles = mol.GetProp('SMILES')
else:
smiles = Chem.MolToSmiles(mol, isomericSmiles=True)
# --- END CHANGE ---

data = Data(
x=x,
Expand Down