示例#1
0
/// Writes \p molecule to the file with \p fileName.
///
/// This static convenience method allows for the writing of molecule
/// to a file without explicitly creating a file object.
void MoleculeFile::quickWrite(const Molecule *molecule, const std::string &fileName)
{
    MoleculeFile file;
    file.addMolecule(const_cast<Molecule *>(molecule));
    file.write(fileName);

    // remove the molecule from the file so that it does
    // not get deleted when this function returns
    file.removeMolecule(const_cast<Molecule *>(molecule));
}
示例#2
0
/// 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;
}