############################################################################ /** * Documentation for this function. */ //function someFunctionName() {} #}}}######################################################################## # MAIN - the beginning of execution for this page ############################################################################ // Security check on filename $file = realpath($_REQUEST['file']); if (!$file || !startsWith($file, realpath($_SESSION['dataDir']))) { mpLog("security:Attempt to access '{$file}' as '{$_REQUEST['file']}'"); die("Security failure: illegal file request '{$_REQUEST['file']}'"); } $tmp = mpTempfile('tmp_pdb_trim_'); reduceTrim($file, $tmp); $name = basename($file); if (preg_match('/H[0-9]*.pdb$/', $name)) { // uses preg_split to split the name into an array with the H from the name missing. $nameArray = preg_split('/H([0-9]*.pdb)$/', $name, -1, PREG_SPLIT_DELIM_CAPTURE); $name = $nameArray[0] . $nameArray[1]; } elseif (preg_match('/H_reg[0-9]*.pdb$/', $name)) { // uses preg_split to split the name into an array with the H from the name missing. $nameArray = preg_split('/H_reg([0-9]*.pdb)$/', $name, -1, PREG_SPLIT_DELIM_CAPTURE); $name = $nameArray[0] . $nameArray[1]; } ### FUNKY: This turns into a binary file download rather than an HTML page, ### and then calls die(), leaving the user on the original HTML page. // These lines may be required by Internet Explorer header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
function onEditPDB() { $req = $_REQUEST; //if($req['cmd'] == 'Cancel') if ($req['cmd'] == 'Go back') { pageGoto("editpdb_setup1.php"); return; } // Otherwise, moving forward: $oldID = $req['modelID']; $oldModel = $_SESSION['models'][$oldID]; $inpath = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS . '/' . $oldModel['pdb']; $newModel = createModel($oldID . "_edit"); $newID = $newModel['id']; $outpath = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS . '/' . $newModel['pdb']; $s = ""; if (is_array($req['removechain']) && count($req['removechain']) > 0) { removeChains($inpath, $outpath, $req['removechain']); $s .= "<p>You created {$newModel['pdb']} by removing chain(s) " . implode(', ', $req['removechain']) . " from {$oldModel['pdb']}.\n"; mpLog("editpdb:Removed chains from a PDB file"); } else { copy($inpath, $outpath); } $resolu = $req['resolution'] + 0; $oldRes = $oldModel['stats']['resolution'] + 0; if ($resolu && ($oldRes == 0 || $oldRes != $resolu)) { $remark2 = sprintf("REMARK 2 \nREMARK 2 RESOLUTION. %.2f ANGSTROMS. \n", $resolu); replacePdbRemark($outpath, $remark2, 2); $s .= "<p>You manually set the resolution for {$newModel['pdb']}.\n"; mpLog("editpdb:Changed/set resolution for a PDB file"); } if ($req['removeHs']) { $newModel = createModel($oldID . "_trimmed"); $newID = $newModel['id']; $outpath = $_SESSION['dataDir'] . '/' . MP_DIR_MODELS . '/' . $newModel['pdb']; reduceTrim($inpath, $outpath); $s .= "<p>You created {$newModel['pdb']} by removing hydrogens from {$oldModel['pdb']}.\n"; mpLog("editpdb:Removed hydrogens from a PDB file"); } $newModel['stats'] = pdbstat($outpath); $newModel['history'] = "Edited {$oldModel['pdb']}"; $newModel['isUserSupplied'] = $oldModel['isUserSupplied']; $_SESSION['models'][$newID] = $newModel; $_SESSION['lastUsedModelID'] = $newID; // this is now the current model $details = describePdbStats($newModel['stats'], true); $s .= "<ul>\n"; foreach ($details as $detail) { $s .= "<li>{$detail}</li>\n"; } $s .= "</ul>\n"; $entrynum = addLabbookEntry("Created PDB file {$newModel['pdb']}", $s, "{$oldID}|{$newID}", "auto", "scissors.png"); pageGoto("generic_done.php", array('labbookEntry' => $entrynum)); }
function removeHydrogens($inpath, $outpath) { $tasks = getProgressTasks(); $tasks['reducetrim'] = "Remove hydrogens to avoid possible conflict with hydrogen lengths"; $tmp1 = mpTempfile("tmp_pdb_"); setProgress($tasks, 'reducetrim'); reduceTrim($inpath, $tmp1); copy($tmp1, $outpath); // Clean up temp files unlink($tmp1); setProgress($tasks, null); // all done }