Exemplo n.º 1
0
/**
* Retrieves the PDB file with the given code from www.rcsb.org
*   pdbcode     the 4-character code identifying the model
* Returns the name of a temporary file, or null if download failed.
*/
function getPdbModel($pdbcode, $biolunit = false)
{
    // I think the PDB website is picky about case
    $pdbcode = strtoupper($pdbcode);
    // Copy in the newly uploaded file:
    if ($biolunit) {
        //$src = "ftp://ftp.rcsb.org/pub/pdb/data/biounit/coordinates/all/".strtolower($pdbcode).".pdb1.gz";
        $src = "http://www.pdb.org/pdb/files/" . strtolower($pdbcode) . ".pdb1.gz";
    } else {
        //$src = "http://www.rcsb.org/pdb/cgi/export.cgi/$pdbcode.pdb?format=PDB&pdbId=$pdbcode&compression=gz";
        $src = "http://www.pdb.org/pdb/files/" . strtolower($pdbcode) . ".pdb.gz";
    }
    $outpath = mpTempfile("tmp_pdb_");
    if (copy($src, $outpath) && filesize($outpath) > 1000) {
        $outpath2 = mpTempfile("tmp_pdb_");
        exec("gunzip -c < {$outpath} > {$outpath2}");
        // can't just gunzip without a .gz ending
        unlink($outpath);
        // Convert MODELs to chain IDs
        if ($biolunit) {
            $outpath = convertModelsToChains($outpath2);
            unlink($outpath2);
            return $outpath;
        } else {
            return $outpath2;
        }
    } else {
        if (file_exists($outpath)) {
            unlink($outpath);
        }
        return null;
    }
}
Exemplo n.º 2
0
 function onConvertToBiolUnit()
 {
     if ($_SESSION['lastUsedModelID']) {
         $oldID = $_SESSION['lastUsedModelID'];
         $model = $_SESSION['ensembles'][$oldID];
         if (!$model) {
             return;
         }
         $modelDir = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS;
         $infile = "{$modelDir}/{$model['pdb']}";
         $tmpfile = convertModelsToChains($infile);
         $newModel = createModel("{$oldID}-biolunit");
         $newID = $newModel['id'];
         $newModel['stats'] = pdbstat($tmpfile);
         $newModel['history'] = 'Converted from ensemble to biological unit';
         $newModel['isUserSupplied'] = $model['isUserSupplied'];
         if (!file_exists($modelDir)) {
             mkdir($modelDir, 0777);
         }
         copy($tmpfile, "{$modelDir}/{$newModel['pdb']}");
         unlink($tmpfile);
         $_SESSION['models'][$newID] = $newModel;
         $_SESSION['lastUsedModelID'] = $newID;
     }
 }