Example usage for java.lang Error Error

List of usage examples for java.lang Error Error

Introduction

In this page you can find the example usage for java.lang Error Error.

Prototype

public Error(Throwable cause) 

Source Link

Document

Constructs a new error with the specified cause and a detail message of (cause==null ?

Usage

From source file:edu.berkeley.compbio.phyloutils.NearestNodeFinder.java

public static void main(String[] argv) throws IOException, NoSuchNodeException {
    //service.setGreengenesRawFilename(argv[0]);
    service.setHugenholtzFilename(argv[0]);
    //service.setSynonymService(NcbiTaxonomyClient.getInstance());
    service.init();//w  w w.ja  v  a  2  s. c  o  m

    final int[] targetIds = IntArrayReader.read(argv[1]);
    int[] queryIds = IntArrayReader.read(argv[2]);
    final double minDistance = Double.parseDouble(argv[3]); // implement leave-one-out at any level

    Map<Integer, Double> results = Parallel.map(new ArrayIterator(queryIds), new Function<Integer, Double>() {
        public Double apply(Integer queryId) {
            try {
                double best = Double.MAX_VALUE;
                for (int targetId : targetIds) {
                    double d = service.minDistanceBetween(queryId, targetId);
                    if (d >= minDistance) {
                        best = Math.min(best, d);
                    }
                }
                return best;
            } catch (NoSuchNodeException e) {
                throw new Error(e);
            }
        }
    });

    String outfileName = argv[4];
    PrintWriter out = new PrintWriter(outfileName);
    out.println("id\tdist");

    for (Map.Entry<Integer, Double> entry : results.entrySet()) {
        out.println(entry.getKey() + "\t" + entry.getValue());
    }
    out.close();
}

From source file:com.genentech.struchk.sdfNormalizer.java

public static void main(String[] args) {
    long start = System.currentTimeMillis();
    int nMessages = 0;
    int nErrors = 0;
    int nStruct = 0;

    // create command line Options object
    Options options = new Options();
    Option opt = new Option("in", true, "input file [.ism,.sdf,...]");
    opt.setRequired(true);//from ww  w.j  a v  a 2s.c  o m
    options.addOption(opt);

    opt = new Option("out", true, "output file");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("mol", true, "molFile used for output: ORIGINAL(def)|NORMALIZED|TAUTOMERIC");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("shortMessage", false,
            "Limit message to first 80 characters to conform with sdf file specs.");
    opt.setRequired(false);
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        exitWithHelp(options, e.getMessage());
        throw new Error(e); // avoid compiler errors
    }
    args = cmd.getArgs();

    if (args.length != 0) {
        System.err.print("Unknown options: " + args + "\n\n");
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("sdfNormalizer", options);
        System.exit(1);
    }

    String molOpt = cmd.getOptionValue("mol");
    OUTMolFormat outMol = OUTMolFormat.ORIGINAL;
    if (molOpt == null || "original".equalsIgnoreCase(molOpt))
        outMol = OUTMolFormat.ORIGINAL;
    else if ("NORMALIZED".equalsIgnoreCase(molOpt))
        outMol = OUTMolFormat.NORMALIZED;
    else if ("TAUTOMERIC".equalsIgnoreCase(molOpt))
        outMol = OUTMolFormat.TAUTOMERIC;
    else {
        System.err.printf("Unkown option for -mol: %s\n", molOpt);
        System.exit(1);
    }

    String inFile = cmd.getOptionValue("in");
    String outFile = cmd.getOptionValue("out");
    boolean limitMessage = cmd.hasOption("shortMessage");

    try {
        oemolistream ifs = new oemolistream(inFile);
        oemolostream ofs = new oemolostream(outFile);

        URL cFile = OEStruchk.getResourceURL(OEStruchk.class, "Struchk.xml");

        // create OEStruchk from config file
        OEStruchk strchk = new OEStruchk(cFile, CHECKConfig.ASSIGNStructFlag, false);

        OEGraphMol mol = new OEGraphMol();
        StringBuilder sb = new StringBuilder(2000);
        while (oechem.OEReadMolecule(ifs, mol)) {
            if (!strchk.applyRules(mol, null))
                nErrors++;

            switch (outMol) {
            case NORMALIZED:
                mol.Clear();
                oechem.OEAddMols(mol, strchk.getTransformedMol("parent"));
                break;
            case TAUTOMERIC:
                mol.Clear();
                oechem.OEAddMols(mol, strchk.getTransformedMol(null));
                break;
            case ORIGINAL:
                break;
            }

            oechem.OESetSDData(mol, "CTISMILES", strchk.getTransformedIsoSmiles(null));
            oechem.OESetSDData(mol, "CTSMILES", strchk.getTransformedSmiles(null));
            oechem.OESetSDData(mol, "CISMILES", strchk.getTransformedIsoSmiles("parent"));
            oechem.OESetSDData(mol, "Strutct_Flag", strchk.getStructureFlag().getName());

            List<Message> msgs = strchk.getStructureMessages(null);
            nMessages += msgs.size();
            for (Message msg : msgs)
                sb.append(String.format("\t%s:%s", msg.getLevel(), msg.getText()));
            if (limitMessage)
                sb.setLength(Math.min(sb.length(), 80));

            oechem.OESetSDData(mol, "NORM_MESSAGE", sb.toString());

            oechem.OEWriteMolecule(ofs, mol);

            sb.setLength(0);
            nStruct++;
        }
        strchk.delete();
        mol.delete();
        ifs.close();
        ifs.delete();
        ofs.close();
        ofs.delete();

    } catch (Exception e) {
        throw new Error(e);
    } finally {
        System.err.printf("sdfNormalizer: Checked %d structures %d errors, %d messages in %dsec\n", nStruct,
                nErrors, nMessages, (System.currentTimeMillis() - start) / 1000);
    }
}

From source file:MondrianService.java

public static void main(String[] arg) {
    System.out.println("Starting Mondrian Connector for Infoveave");
    Properties prop = new Properties();
    InputStream input = null;/*  w  w  w  . ja  v a2  s  . c  o  m*/
    int listenPort = 9998;
    int threads = 100;
    try {
        System.out.println("Staring from :" + getSettingsPath());
        input = new FileInputStream(getSettingsPath() + File.separator + "MondrianService.properties");
        prop.load(input);
        listenPort = Integer.parseInt(prop.getProperty("port"));
        threads = Integer.parseInt(prop.getProperty("maxThreads"));
        if (input != null) {
            input.close();
        }
        System.out.println("Found MondrianService.Properties");
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
    }

    port(listenPort);
    threadPool(threads);
    enableCORS("*", "*", "*");

    ObjectMapper mapper = new ObjectMapper();
    MondrianConnector connector = new MondrianConnector();
    get("/ping", (request, response) -> {
        response.type("application/json");
        return "\"Here\"";
    });

    post("/cubes", (request, response) -> {
        response.type("application/json");
        try {
            Query queryObject = mapper.readValue(request.body(), Query.class);
            response.status(200);
            return mapper.writeValueAsString(connector.GetCubes(queryObject));
        } catch (JsonParseException ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        } catch (Exception ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        }
    });

    post("/measures", (request, response) -> {
        response.type("application/json");
        try {
            Query queryObject = mapper.readValue(request.body(), Query.class);
            response.status(200);
            return mapper.writeValueAsString(connector.GetMeasures(queryObject));
        } catch (JsonParseException ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        } catch (Exception ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        }
    });

    post("/dimensions", (request, response) -> {
        response.type("application/json");
        try {
            Query queryObject = mapper.readValue(request.body(), Query.class);
            response.status(200);
            return mapper.writeValueAsString(connector.GetDimensions(queryObject));
        } catch (JsonParseException ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        } catch (Exception ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        }
    });

    post("/cleanCache", (request, response) -> {
        response.type("application/json");
        try {
            Query queryObject = mapper.readValue(request.body(), Query.class);
            response.status(200);
            return mapper.writeValueAsString(connector.CleanCubeCache(queryObject));
        } catch (JsonParseException ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        } catch (Exception ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        }
    });

    post("/executeQuery", (request, response) -> {
        response.type("application/json");
        try {
            Query queryObject = mapper.readValue(request.body(), Query.class);
            response.status(200);
            String content = mapper.writeValueAsString(connector.ExecuteQuery2(queryObject));
            return content;
        } catch (JsonParseException ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        } catch (Exception ex) {
            response.status(400);
            return mapper.writeValueAsString(new Error(ex.getMessage()));
        }
    });
}

From source file:com.genentech.chemistry.openEye.apps.SDFSubRMSD.java

public static void main(String... args) throws IOException { // create command line Options object
    Options options = new Options();
    Option opt = new Option("in", true, "input file oe-supported");
    opt.setRequired(true);/*from   w  ww. ja  v  a  2s .c o  m*/
    options.addOption(opt);

    opt = new Option("out", true, "output file oe-supported");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("fragFile", true, "file with single 3d substructure query");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("isMDL", false,
            "if given the fragFile is suposed to be an mdl query file, query features are supported.");
    opt.setRequired(false);
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    String inFile = cmd.getOptionValue("in");
    String outFile = cmd.getOptionValue("out");
    String fragFile = cmd.getOptionValue("fragFile");

    // read fragment
    OESubSearch ss;
    oemolistream ifs = new oemolistream(fragFile);
    OEMolBase mol;
    if (!cmd.hasOption("isMDL")) {
        mol = new OEGraphMol();
        oechem.OEReadMolecule(ifs, mol);
        ss = new OESubSearch(mol, OEExprOpts.AtomicNumber, OEExprOpts.BondOrder);
    } else {
        int aromodel = OEIFlavor.Generic.OEAroModelOpenEye;
        int qflavor = ifs.GetFlavor(ifs.GetFormat());
        ifs.SetFlavor(ifs.GetFormat(), (qflavor | aromodel));
        int opts = OEMDLQueryOpts.Default | OEMDLQueryOpts.SuppressExplicitH;
        OEQMol qmol = new OEQMol();
        oechem.OEReadMDLQueryFile(ifs, qmol, opts);
        ss = new OESubSearch(qmol);
        mol = qmol;
    }

    double nSSatoms = mol.NumAtoms();
    double sssCoords[] = new double[mol.GetMaxAtomIdx() * 3];
    mol.GetCoords(sssCoords);
    mol.Clear();
    ifs.close();

    if (!ss.IsValid())
        throw new Error("Invalid query " + args[0]);

    ifs = new oemolistream(inFile);
    oemolostream ofs = new oemolostream(outFile);
    int count = 0;

    while (oechem.OEReadMolecule(ifs, mol)) {
        count++;
        double rmsd = Double.MAX_VALUE;
        double molCoords[] = new double[mol.GetMaxAtomIdx() * 3];
        mol.GetCoords(molCoords);

        for (OEMatchBase mb : ss.Match(mol, false)) {
            double r = 0;
            for (OEMatchPairAtom mp : mb.GetAtoms()) {
                OEAtomBase asss = mp.getPattern();
                double sx = sssCoords[asss.GetIdx() * 3];
                double sy = sssCoords[asss.GetIdx() * 3];
                double sz = sssCoords[asss.GetIdx() * 3];

                OEAtomBase amol = mp.getTarget();
                double mx = molCoords[amol.GetIdx() * 3];
                double my = molCoords[amol.GetIdx() * 3];
                double mz = molCoords[amol.GetIdx() * 3];

                r += Math.sqrt((sx - mx) * (sx - mx) + (sy - my) * (sy - my) + (sz - mz) * (sz - mz));
            }
            r /= nSSatoms;
            rmsd = Math.min(rmsd, r);
        }

        if (rmsd != Double.MAX_VALUE)
            oechem.OESetSDData(mol, "SSSrmsd", String.format("%.3f", rmsd));

        oechem.OEWriteMolecule(ofs, mol);
        mol.Clear();
    }

    ifs.close();
    ofs.close();

    mol.delete();
    ss.delete();
}

From source file:com.genentech.struchk.OEMDLPercieveChecker.java

public static void main(String[] args) throws ParseException, JDOMException, IOException {
    // create command line Options object
    Options options = new Options();
    Option opt = new Option("i", true, "input file [.ism,.sdf,...]");
    opt.setRequired(true);/*from  w w  w.j  av  a  2s.c o  m*/
    options.addOption(opt);

    opt = new Option("o", true, "output file");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("d", false, "debug: wait for user to press key at startup.");
    opt.setRequired(false);
    options.addOption(opt);

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    if (cmd.hasOption("d")) {
        System.err.println("Start debugger and press return:");
        new BufferedReader(new InputStreamReader(System.in)).readLine();
    }

    if (args.length != 0) {
        exitWithHelp(options);
    }

    String inFile = cmd.getOptionValue("i");
    String outFile = cmd.getOptionValue("o");

    OEMDLPercieveChecker checker = null;
    try {
        checker = new OEMDLPercieveChecker();

        oemolostream out = new oemolostream(outFile);
        oemolistream in = new oemolistream(inFile);

        OEGraphMol mol = new OEGraphMol();
        while (oechem.OEReadMolecule(in, mol)) {
            if (!checker.checkMol(mol))
                oechem.OEWriteMolecule(out, mol);
        }
        checker.delete();
        in.close();
        in.delete();

        out.close();
        out.delete();

    } catch (Exception e) {
        throw new Error(e);
    }
    System.err.println("Done:");
}

From source file:com.genentech.retrival.tabExport.TABExporter.java

public static void main(String[] args) throws ParseException, JDOMException, IOException {
    long start = System.currentTimeMillis();
    int nStruct = 0;

    // create command line Options object
    Options options = new Options();
    Option opt = new Option("sqlFile", true, "sql-xml file");
    opt.setRequired(true);/* w w  w  .  j  av  a2 s  . c o  m*/
    options.addOption(opt);

    opt = new Option("sqlName", true, "name of SQL element in xml file");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("o", true, "output file");
    opt.setRequired(false);
    options.addOption(opt);

    opt = new Option("newLineReplacement", true,
            "If given newlines in fields will be replaced by this string.");
    options.addOption(opt);

    opt = new Option("noHeader", false, "Do not output header line");
    options.addOption(opt);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        System.err.println(e.getMessage());
        exitWithHelp(options);
    }
    args = cmd.getArgs();

    String outFile = cmd.getOptionValue("o");
    String sqlFile = cmd.getOptionValue("sqlFile");
    String sqlName = cmd.getOptionValue("sqlName");
    String newLineReplacement = cmd.getOptionValue("newLineReplacement");

    args = cmd.getArgs();

    try {
        PrintStream out = System.out;
        if (outFile != null)
            out = new PrintStream(outFile);

        SQLStatement stmt = SQLStatement.createFromFile(new File(sqlFile), sqlName);
        Object[] sqlArgs = args;
        if (stmt.getParamTypes().length != args.length) {
            System.err.printf(
                    "\nWarining sql statement needs %d parameters but got only %d. Filling up with NULLs.\n",
                    stmt.getParamTypes().length, args.length);
            sqlArgs = new Object[stmt.getParamTypes().length];
            System.arraycopy(args, 0, sqlArgs, 0, args.length);
        }

        Selecter sel = Selecter.factory(stmt);
        if (!sel.select(sqlArgs)) {
            System.err.println("No rows returned!");
            System.exit(0);
        }

        String[] fieldNames = sel.getFieldNames();
        if (fieldNames.length == 0) {
            System.err.println("Query did not return any columns");
            exitWithHelp(options);
        }

        if (!cmd.hasOption("noHeader")) {
            StringBuilder sb = new StringBuilder(200);
            for (String f : fieldNames)
                sb.append(f).append('\t');
            if (sb.length() > 1)
                sb.setLength(sb.length() - 1); // chop last \t
            String header = sb.toString();

            out.println(header);
        }

        StringBuilder sb = new StringBuilder(200);
        while (sel.hasNext()) {
            Record sqlRec = sel.next();
            sb.setLength(0);

            for (int i = 0; i < fieldNames.length; i++) {
                String fld = sqlRec.getStrg(i);
                if (newLineReplacement != null)
                    fld = NEWLinePattern.matcher(fld).replaceAll(newLineReplacement);

                sb.append(fld).append('\t');
            }

            if (sb.length() > 1)
                sb.setLength(sb.length() - 1); // chop last \t
            String row = sb.toString();

            out.println(row);

            nStruct++;
        }

    } catch (Exception e) {
        throw new Error(e);
    } finally {
        System.err.printf("TABExporter: Exported %d records in %dsec\n", nStruct,
                (System.currentTimeMillis() - start) / 1000);
    }
}

From source file:com.genentech.chemistry.tool.align.SDFAlign.java

public static void main(String... args) {
    Options options = new Options();
    Option opt = new Option("in", true, "input sd file");
    opt.setRequired(true);//from  www.  j a v a 2 s .  c o  m
    options.addOption(opt);

    opt = new Option("out", true, "output file");
    opt.setRequired(true);
    options.addOption(opt);

    opt = new Option("method", true, "fss|sss|MCS|clique (default mcs).");
    options.addOption(opt);

    opt = new Option("ref", true,
            "reference molecule if not given first in file is used. If multiple ref molecules are read the min RMSD is reported");
    options.addOption(opt);

    opt = new Option("mirror", false, "If given and the molecule is not chiral, return best mirror image.");
    options.addOption(opt);

    opt = new Option("rmsdTag", true, "Tagname for output of rmsd, default: no output.");
    options.addOption(opt);

    opt = new Option("atomMatch", true,
            "Sequence of none|default|hcount|noAromatic specifing how atoms are matched cf. oe document.\n"
                    + "noAromatic can be used to make terminal atoms match aliphatic and aromatic atoms.\n"
                    + "Queryfeatures are considered only if default is used.");
    options.addOption(opt);

    opt = new Option("bondMatch", true,
            "Sequence of none|default specifing how bonds are matched cf. oe document.");
    options.addOption(opt);

    opt = new Option("keepCoreHydrogens", false,
            "If not specified the hydrigen atoms are removed from the core.");
    options.addOption(opt);

    opt = new Option("outputMol", true, "aligned|original (def: aligned) use original to just compute rmsd.");
    options.addOption(opt);

    opt = new Option("doNotOptimize", false,
            "If specified the RMSD is computed without moving optimizing the overlay.");
    options.addOption(opt);

    opt = new Option("quiet", false, "Reduced warining messages");
    options.addOption(opt);

    CommandLineParser parser = new BasicParser();
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
    } catch (Exception e) {
        exitWithHelp(e.getMessage(), options);
    }

    if (cmd.getArgs().length > 0)
        exitWithHelp("To many arguments", options);

    // do not check aromaticity on atoms so that a terminal atom matches aromatic and non aromatic atoms
    int atomExpr = OEExprOpts.DefaultAtoms;
    int bondExpr = OEExprOpts.DefaultBonds;

    String atomMatch = cmd.getOptionValue("atomMatch");
    if (atomMatch == null)
        atomMatch = "";
    atomMatch = '|' + atomMatch.toLowerCase() + '|';

    String bondMatch = cmd.getOptionValue("bondMatch");
    if (bondMatch == null)
        bondMatch = "";
    bondMatch = '|' + bondMatch.toLowerCase() + '|';

    String inFile = cmd.getOptionValue("in");
    String outFile = cmd.getOptionValue("out");
    String refFile = cmd.getOptionValue("ref");
    String method = cmd.getOptionValue("method");
    String rmsdTag = cmd.getOptionValue("rmsdTag");
    String oMol = cmd.getOptionValue("outputMol");
    boolean doMirror = cmd.hasOption("mirror");
    boolean doOptimize = !cmd.hasOption("doNotOptimize");
    boolean quiet = cmd.hasOption("quiet");

    OUTType outputMol = oMol == null ? OUTType.ALIGNED : OUTType.valueOf(oMol.toUpperCase());

    if (atomMatch.startsWith("|none"))
        atomExpr = 0;
    if (atomMatch.contains("|hcount|"))
        atomExpr |= OEExprOpts.HCount;
    if (atomMatch.contains("|noAromatic|"))
        atomExpr &= (~OEExprOpts.Aromaticity);

    if (bondMatch.startsWith("|none"))
        bondExpr = 0;

    ArrayList<OEMol> refmols = new ArrayList<OEMol>();
    if (refFile != null) {
        oemolistream reffs = new oemolistream(refFile);
        if (!is3DFormat(reffs.GetFormat()))
            oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates");
        reffs.SetFormat(OEFormat.MDL);

        int aromodel = OEIFlavor.Generic.OEAroModelOpenEye;
        int qflavor = reffs.GetFlavor(reffs.GetFormat());
        reffs.SetFlavor(reffs.GetFormat(), (qflavor | aromodel));

        OEMol rmol = new OEMol();
        while (oechem.OEReadMDLQueryFile(reffs, rmol)) {
            if (!cmd.hasOption("keepCoreHydrogens"))
                oechem.OESuppressHydrogens(rmol);
            refmols.add(rmol);
            rmol = new OEMol();
        }
        rmol.delete();

        if (refmols.size() == 0)
            throw new Error("reference file had no entries");

        reffs.close();
    }

    oemolistream fitfs = new oemolistream(inFile);
    if (!is3DFormat(fitfs.GetFormat()))
        oechem.OEThrow.Fatal("Invalid input format: need 3D coordinates");

    oemolostream ofs = new oemolostream(outFile);
    if (!is3DFormat(ofs.GetFormat()))
        oechem.OEThrow.Fatal("Invalid output format: need 3D coordinates");

    AlignInterface aligner = null;
    OEGraphMol fitmol = new OEGraphMol();

    if (oechem.OEReadMolecule(fitfs, fitmol)) {
        if (refmols.size() == 0) {
            OEMol rmol = new OEMol(fitmol);
            if (!cmd.hasOption("keepCoreHydrogens"))
                oechem.OESuppressHydrogens(rmol);

            refmols.add(rmol);
        }

        if ("sss".equalsIgnoreCase(method)) {
            aligner = new SSSAlign(refmols, outputMol, rmsdTag, doOptimize, doMirror, atomExpr, bondExpr,
                    quiet);

        } else if ("clique".equalsIgnoreCase(method)) {
            aligner = new CliqueAlign(refmols, outputMol, rmsdTag, doOptimize, doMirror, atomExpr, bondExpr,
                    quiet);

        } else if ("fss".equalsIgnoreCase(method)) {
            if (cmd.hasOption("atomMatch") || cmd.hasOption("bondMatch"))
                exitWithHelp("method fss does not support '-atomMatch' or '-bondMatch'", options);
            aligner = new FSSAlign(refmols, outputMol, rmsdTag, doOptimize, doMirror);

        } else {
            aligner = new McsAlign(refmols, outputMol, rmsdTag, doOptimize, doMirror, atomExpr, bondExpr,
                    quiet);
        }

        do {
            aligner.align(fitmol);
            oechem.OEWriteMolecule(ofs, fitmol);
        } while (oechem.OEReadMolecule(fitfs, fitmol));

    }

    fitmol.delete();
    if (aligner != null)
        aligner.close();
    for (OEMolBase mol : refmols)
        mol.delete();
    fitfs.close();
    ofs.close();
}

From source file:com.genentech.chemistry.tool.SDFFilter.java

public static void main(String args[]) {
    String usage = "java sdfFilter [options]\n" + "Filters out molecules that contain the following:\n"
            + "1. More than maxHeavy atoms (default is 100)\n" + "2. Have more than one component\n"
            + "3. Does not have any atoms\n" + "4. Have invalid atoms, like R, * etc ...\n"
            + "5. Have atomic number greater than 53 (Iodine)";

    // create Options object
    Options options = new Options();
    // add  options
    options.addOption("h", false, "");
    options.addOption("in", true, "inFile in OE formats: Ex: a.sdf or .sdf");
    options.addOption("out", true, "outFile in OE formats. Ex: a.sdf or .sdf");
    options.addOption("filtered", true, "Optional: filteredFile in OE formats. Ex: a.sdf or .sdf");
    options.addOption("maxHeavy", true, "Number of heavy atom cutoff. Default is 100");
    CommandLineParser parser = new PosixParser();

    try {//  w w  w .  j a v  a2 s .  com
        CommandLine cmd = parser.parse(options, args);
        String inFile = cmd.getOptionValue("in");
        if (inFile == null) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(usage, options);
            System.exit(1);
        }

        String outFile = cmd.getOptionValue("out");
        if (outFile == null) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(usage, options);
            System.exit(1);
        }

        String filteredFile = null;
        if (cmd.hasOption("filtered")) {
            filteredFile = cmd.getOptionValue("filtered");
        }

        int maxHeavy = 100;
        if (cmd.hasOption("maxHeavy")) {
            maxHeavy = Integer.parseInt(cmd.getOptionValue("maxHeavy"));
            maxAtoms = maxHeavy;
        }

        if (cmd.hasOption("h")) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(usage, options);
            System.exit(1);
        }

        oemolistream ifs = new oemolistream(inFile);
        oemolostream ofs = new oemolostream(outFile);
        oemolostream ffs = null;
        if (filteredFile != null) {
            ffs = new oemolostream(filteredFile);
        }
        /*it appears that we don't have license to molprop toolkit
        oeisstream iss = new oeisstream();
        OEFilter filter = new OEFilter(iss);
        filter.SetTypeCheck(true);
        oechem.OEThrow.SetLevel(OEErrorLevel.Warning);
        */

        OEGraphMol mol = new OEGraphMol();

        while (oechem.OEReadMolecule(ifs, mol)) {
            //            if (passFilters(mol, filter)) { //needs license to molprop toolkit
            if (passFilters(mol)) {
                oechem.OEWriteMolecule(ofs, mol);
            } else {
                if (ffs != null) {
                    oechem.OEWriteMolecule(ffs, mol);
                }
            }
        }

    } catch (ParseException e) { // TODO print explaination
        throw new Error(e);
    }
}

From source file:Main.java

public static String URLEncode(String string) {
    try {//from www  .jav a 2  s.c o  m
        return URLEncoder.encode(string, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        throw new Error(e.getMessage());
    }
}

From source file:Main.java

public static void assertSwingThread() {
    if (!SwingUtilities.isEventDispatchThread())
        throw new Error("Must be Swing event dispatching thread, but detected '"
                + Thread.currentThread().getName() + '\'');
}