[QUESTION]: generating MoleculeDataset with SMILES and additional features (NOT CSV INPUT)
See original GitHub issueWhat are you trying to do?
I have a GCNN model built using chemprop that takes SMILES and an additional (binary) feature as inputs. When predicting test compounds, I am not loading data from a CSV file (in this case I could simply provide path to the file containing additional features for the test compounds as an argument to chemprop_predict
method). But I have the SMILES available in a list object in Python. So, I went ahead and tried to generate a MoleculeDataset object using the utility method get_data_from_smiles
available in chemprop/data/utils.py
. But I see that the method takes a list of feature generators as argument but not the additional features. Therefore, I modified the method as follows:
Previous attempts
def get_data_from_smiles_with_additional_features(smiles: List[str],
skip_invalid_smiles: bool = True,
logger: Logger = None,
features: List = None,
features_generator: List[str] = None) -> MoleculeDataset:
"""
Converts SMILES to a MoleculeDataset.
:param smiles: A list of SMILES strings.
:param skip_invalid_smiles: Whether to skip and filter out invalid smiles.
:param logger: Logger.
:param features: List of additional features
:param features_generator: List of features generators.
:return: A MoleculeDataset with all of the provided SMILES.
"""
debug = logger.debug if logger is not None else print
data = MoleculeDataset([
MoleculeDatapoint(
smiles=smile,
features=feature,
row=OrderedDict({'smiles': smile}),
features_generator=features_generator
) for smile, feature in zip(smiles, features)
])
# Filter out invalid SMILES
if skip_invalid_smiles:
original_data_len = len(data)
data = filter_invalid_smiles(data)
if len(data) < original_data_len:
debug(f'Warning: {original_data_len - len(data)} SMILES are invalid.')
return data
Question The predictions I obtain using this method match the predictions from command line when using an additional file with the same features. However, I have only used a single feature (i.e., one column in a file). Is there a better way to deal with this when I have multiple additional features?
Thank you, Vishal
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
@iwwwish You can use the above code to get the size of molecular features. I will close this issue now. If you have other questions about Chemprop, feel free to open a new issue.
That worked! Thank you.
Is there a way to obtain information from the model file itself whether it takes additional features as input and if yes, the expected shape of the additional features?
Best, Vishal