Beispiel #1
0
/// Downloads and returns the file containing the compounds with ID's
/// in the list \p ids. If an error occurs \c 0 is returned.
///
/// The ownership of the file is passed to the caller.
///
/// For example, to download the file containing %PubChem Compounds
/// 1, 2, 3, 42 and 57:
/// \code
/// QStringList ids;
/// ids << "1" << "2" << "3" << "42" << "57";
/// MoleculeFile *file = pubchem.downloadFile(ids);
/// \endcode
MoleculeFile* PubChem::downloadFile(const QStringList &ids) const
{
    QByteArray data = downloadFileData(ids, "sdf");
    if(data.isEmpty()){
        return 0;
    }

    std::stringstream buffer(std::string(data.constData(), data.size()));

    MoleculeFile *file = new MoleculeFile;
    file->read(buffer, "sdf");

    return file;
}
Beispiel #2
0
/// Downloads and returns the file containing the compounds with ID's
/// in the list \p ids. If an error occurs \c 0 is returned.
///
/// The ownership of the file is passed to the caller.
///
/// For example, to download the file containing %PubChem Compounds
/// 1, 2, 3, 42 and 57:
/// \code
/// QStringList ids;
/// ids << "1" << "2" << "3" << "42" << "57";
/// MoleculeFile *file = pubchem.downloadFile(ids);
/// \endcode
MoleculeFile* PubChem::downloadFile(const QStringList &ids) const
{
    QByteArray data = downloadFileData(ids, "sdf");
    if(data.isEmpty()){
        return 0;
    }

    QBuffer buffer;
    buffer.setData(data);
    buffer.open(QBuffer::ReadOnly);

    MoleculeFile *file = new MoleculeFile;
    file->read(&buffer, "sdf");

    return file;
}
/// Downloads and returns the ligand molecule with \p name. If an
/// error occurs \c 0 is returned.
///
/// The ownership of the returned molecule is passed to the caller.
///
/// For example, to download the heme ligand (named "HEM"):
/// \code
/// Molecule *heme = pdb.downloadLigand("HEM");
/// \endcode
Molecule* ProteinDataBank::downloadLigand(const QString &name) const
{
    QString url("%1/pdb/files/ligand/%2_ideal.sdf");

    QByteArray data = DownloadThread::download(url.arg(d->url.toString()).arg(name.toUpper()));
    if(data.isEmpty()){
        return 0;
    }

    std::stringstream buffer(std::string(data.constData(), data.size()));

    MoleculeFile file;
    bool ok = file.read(buffer, "sdf");

    if(!ok || file.isEmpty()){
        return 0;
    }

    Molecule *molecule = file.molecule();
    file.removeMolecule(molecule);

    return molecule;
}