getCompoundProperties method
- int cid
Fetches compound properties from PubChem using the given CID.
Returns a map containing compound details like name, formula, weight, and SMILES.
Implementation
Future<Map<String, dynamic>> getCompoundProperties(int cid) async {
final url = Uri.parse('$chempubBaseUrl/compound/cid/$cid/JSON');
final response = await http.get(url);
if (response.statusCode != 200) {
throw Exception('Failed to fetch properties for CID $cid');
}
final data = jsonDecode(response.body);
final properties = data['PC_Compounds'][0]['props'];
final name = _findProperty(properties, 'IUPAC Name') ?? 'Unnamed compound';
final formula = _findProperty(properties, 'Molecular Formula') ?? 'N/A';
final weight = _findProperty(properties, 'Molecular Weight') ?? 'N/A';
final smiles = _findProperty(properties, 'Canonical SMILES') ?? 'N/A';
final hbDonor =
_findivalPropertybylabel(properties, 'Hydrogen Bond Donor', 'Count') ??
'N/A';
final hbAcceptor = _findivalPropertybylabel(
properties, 'Hydrogen Bond Acceptor', 'Count') ??
'N/A';
final tpsa = _findfvalPropertybylabel(
properties, 'Polar Surface Area', 'Topological') ??
'N/A';
final complexity =
_findfvalPropertybylabelonly(properties, 'Compound Complexity') ??
'N/A';
final charge = _findProperty(properties, 'Charge') ?? 'N/A';
final title = _findProperty(properties, 'Title') ?? 'N/A';
final xlogp =
_findfvalPropertybylabel(properties, 'XLogP3', 'Log P') ?? 'N/A';
return {
'cid': cid,
'name': name,
'formula': formula,
'weight': weight,
'SMILES': smiles,
'Hydrogen Bond Donor': hbDonor,
'Hydrogen Bond Acceptor': hbAcceptor,
'TPSA': tpsa,
'Complexity': complexity,
'charge ': charge,
'Title': title,
'XLogP': xlogp,
};
}