Exemplo n.º 1
0
     }
     $pos = 0;
 }
 // remove CR if present (IE, Mozilla et al.) and add it again (for Opera)
 $mol = str_replace("\r\n", "\n", $mol);
 $mol = str_replace("\n", "\r\n", $mol);
 //$saferxn = escapeshellcmd($mol);
 $saferxn = str_replace(";", " ", $mol);
 $saferxn = str_replace("\"", " ", $saferxn);
 $saferxn = str_replace("\\'", " ", $saferxn);
 $saferxn = str_replace("\\´", " ", $saferxn);
 $saferxn = str_replace("\\`", " ", $saferxn);
 $saferxn = str_replace("\\|", " ", $saferxn);
 $rxndescr = analyze_rxnfile($saferxn);
 $nrmol = get_nrmol($rxndescr);
 $npmol = get_npmol($rxndescr);
 //echo "there are $nrmol reactants and $npmol products<br>\n";
 if ($nrmol == 0 || $npmol == 0) {
     echo "incomplete reaction file!\n";
     echo "</body></html>\n";
     die;
 }
 $allmol = array();
 $rmol = array();
 $pmol = array();
 $label_list = array();
 $map_list = array();
 $n_labels = 0;
 $n_maps = 0;
 $mapstr = "";
 $allmol = explode("\$MOL\r\n", $saferxn);
Exemplo n.º 2
0
function apply_maps($myrxn, $mymap)
{
    $result = "";
    $rxndescr = analyze_rxnfile($myrxn);
    $nrmol = get_nrmol($rxndescr);
    $npmol = get_npmol($rxndescr);
    $allmol = array();
    $allmol = explode("\$MOL\r\n", $myrxn);
    $ca = count($allmol);
    $header = $allmol[0];
    $rlabel_list = array();
    $plabel_list = array();
    $map_list = array();
    $n_rlabels = 0;
    $n_plabels = 0;
    $n_maps = 0;
    if (strlen($mymap) > 0) {
        $map_list = explode(",", $mymap);
        $n_maps = count($map_list);
    }
    if ($nrmol > 0 && $npmol > 0) {
        if ($nrmol > 0) {
            for ($i = 0; $i < $nrmol; $i++) {
                $rmol[$i] = $allmol[$i + 1];
                $mnum = $i + 1;
                $mid = "r" . $mnum;
            }
        }
        if ($npmol > 0) {
            for ($i = 0; $i < $npmol; $i++) {
                $pmol[$i] = $allmol[$i + 1 + $nrmol];
                $mnum = $i + 1;
                $labels = get_atomlabels($pmol[$i]);
                $mid = "p" . $mnum;
            }
        }
        $l = 1;
        foreach ($map_list as $item) {
            $marr1 = explode("=", $item);
            $rpart = $marr1[0];
            $rarr1 = explode(":", $rpart);
            $rm = $rarr1[0];
            $rm = intval(str_replace("r", "", $rm));
            $ra = $rarr1[1];
            $rl = $l;
            $ppart = $marr1[1];
            $parr1 = explode(":", $ppart);
            $pm = $parr1[0];
            $pm = intval(str_replace("p", "", $pm));
            $pa = $parr1[1];
            $pl = $l;
            @($rlbl = $rlabel_list[$rm - 1]);
            if (strlen($rlbl) > 0) {
                $rlbl .= ",";
            }
            $rlbl .= $ra . "-" . $rl;
            $rlabel_list[$rm - 1] = $rlbl;
            @($plbl = $plabel_list[$pm - 1]);
            if (strlen($plbl) > 0) {
                $plbl .= ",";
            }
            $plbl .= $pa . "-" . $pl;
            $plabel_list[$pm - 1] = $plbl;
            $l++;
        }
        for ($i = 0; $i < $nrmol; $i++) {
            $lbl = $rlabel_list[$i];
        }
        for ($i = 0; $i < $npmol; $i++) {
            $lbl = $plabel_list[$i];
        }
        $newrxn = $header;
        for ($i = 0; $i < $nrmol; $i++) {
            $rmol[$i] = apply_labels($rmol[$i], $rlabel_list[$i]);
            $newrxn .= "\$MOL\r\n" . $rmol[$i];
        }
        for ($i = 0; $i < $npmol; $i++) {
            $pmol[$i] = apply_labels($pmol[$i], $plabel_list[$i]);
            $newrxn .= "\$MOL\r\n" . $pmol[$i];
        }
        $result = $newrxn;
    }
    // end if there are both reactants and products
    return $result;
}