Пример #1
0
<?php

include_once '/usr/local/lib/openbabel.php';
$obMol = new OBMol();
$obMol->NewAtom();
$numAtoms = $obMol->NumAtoms();
# now 1 atom
$obMol->NewAtom();
$obMol->AddBond(1, 2, 1);
$numBonds = $obMol->NumBonds();
# now 1 bond
$obMol->Clear();
$obConversion = new OBConversion();
$obConversion->SetInAndOutFormats("smi", "svg");
$obConversion->ReadString($obMol, "C1=CC=CS1");
$numAtoms = $obMol->NumAtoms();
# now 5 atoms
$obMol->AddHydrogens();
$numAtoms = $obMol->NumAtoms();
# now 9 atoms
$outMDL = $obConversion->WriteString($obMol);
echo $outMDL;
Пример #2
0
function readstring($format, $string, $opt = array())
{
    # setup converter
    $OBConversion = new \OBConversion();
    $OBConversion->SetInFormat($format);
    # set options
    if (!empty($opt)) {
        foreach ($opt as $k => $v) {
            if (!empty($v)) {
                $OBConversion->AddOption($k, $OBConversion::INOPTIONS, $v);
            } else {
                $OBConversion->AddOption($k, $OBConversion::INOPTIONS);
            }
        }
    }
    $OBMol = new \OBMol();
    $OBConversion->ReadString($OBMol, $string);
    return new Molecule($OBMol);
}