predict.py
AI for Chemistry/code/chemprop_VP-main (1)/chemprop_VP-main/chemprop/train/predict.py
from typing import List
import torch
from tqdm import tqdm
from chemprop.data import MoleculeDataLoader, MoleculeDataset, StandardScaler
from chemprop.models import MoleculeModel
def predict(model: MoleculeModel,
data_loader: MoleculeDataLoader,
disable_progress_bar: bool = False,
scaler: StandardScaler = None) -> List[List[float]]:
"""
Makes predictions on a dataset using an ensemble of models.
:param model: A :class:`~chemprop.models.model.MoleculeModel`.
:param data_loader: A :class:`~chemprop.data.data.MoleculeDataLoader`.
:param disable_progress_bar: Whether to disable the progress bar.
:param scaler: A :class:`~chemprop.features.scaler.StandardScaler` object fit on the training targets.
:return: A list of lists of predictions. The outer list is molecules while the inner list is tasks.
"""
model.eval()
preds = []
for batch in tqdm(data_loader, disable=disable_progress_bar, leave=False):
# Prepare batch
batch: MoleculeDataset
mol_batch, features_batch, atom_descriptors_batch, atom_features_batch, bond_features_batch = \
batch.batch_graph(), batch.features(), batch.atom_descriptors(
), batch.atom_features(), batch.bond_features()
smiles_batch = batch.smiles()
T_batch = torch.Tensor(batch.temperatures()).unsqueeze(-1)
if next(model.parameters()).is_cuda:
T_batch = T_batch.cuda()
# Make predictions
with torch.no_grad():
batch_preds = model(mol_batch, features_batch, atom_descriptors_batch,
atom_features_batch, bond_features_batch, T_batch, smiles_batch)
batch_preds = batch_preds.data.cpu().numpy()
# Inverse scale if regression
if scaler is not None:
batch_preds = scaler.inverse_transform(batch_preds)
# Collect vectors
batch_preds = batch_preds.tolist()
preds.extend(batch_preds)
return preds
相关文章
cosmo_to_s_profile_ver_1.1.1.py
cosmo_to_s_profile_ver_1.1.1.py — python source code from the AI for Chemistry learning materials (AI for Chemistry/2025_COSMO/data/s-profiles-all/List-9/cosmo_to_s_profile_ver_1.1.1.py).
阅读文章 →area.py
area.py — python source code from the AI for Chemistry learning materials (AI for Chemistry/2025_COSMO/data/s-profiles-all/area_volume-org/area.py).
阅读文章 →area_volume.py
area_volume.py — python source code from the AI for Chemistry learning materials (AI for Chemistry/2025_COSMO/data/s-profiles-all/area_volume-org/area_volume.py).
阅读文章 →volume.py
volume.py — python source code from the AI for Chemistry learning materials (AI for Chemistry/2025_COSMO/data/s-profiles-all/area_volume-org/volume.py).
阅读文章 →check_final_CID.py
check_final_CID.py — python source code from the AI for Chemistry learning materials (AI for Chemistry/2025_COSMO/data/s-profiles-all/check/check_final_CID.py).
阅读文章 →check_for_CID.py
check_for_CID.py — python source code from the AI for Chemistry learning materials (AI for Chemistry/2025_COSMO/data/s-profiles-all/check/check_for_CID.py).
阅读文章 →