Command Line Interface and Options¶
This chapter describes how Options classes that are derived from
OEOptions can be configured with command line
inputs passed in through argv
.
The OEConfigureOpts function is a convenience function
that takes an OEOptions derivative options class and
the command line arguments argv
, parses the command line arguments,
and configures the option parameters with command line inputs. A
OEInterface is generated internally from the
OEOptions, which performs the command lines parsing.
Note that this only applies to Options classes that are derived from the OEOptions. There are a handful of Options classes that still does not derive from OEOptions, and hence cannot be configured with command line inputs directly. Command Line Interface Definitions is an alternative way to work with command line interfaces for such cases.
In addition to the convenience function OEConfigureOpts, two additional general purpose Options classes, OESimpleAppOptions, and OERefInputAppOptions, are provided that extends any other options classes to include necessary input/output parameters that are generally required to create an application.
See also
OEConfigureOpts
functionOEOptions class
OESimpleAppOptions class
OERefInputAppOptions class
Application with Input, output, and Options¶
The following example shows how to use the OESimpleAppOptions class to extend an Options class with an additional input and output file.
The specific example is taken from OEDocking, and uses the
the OEMakeReceptor
function to make a receptor in
a design unit. In this example, the OEMakeReceptorOptions
is extended with an input and output.
Listing 1: Application with input, output, and options (Making Receptor)
/*
(C) 2022 Cadence Design Systems, Inc. (Cadence)
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED. OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEBio;
using OpenEye.OEDocking;
public class MakeReceptor
{
public static void Main(string[] argv)
{
OEMakeReceptorOptions recOpts = new OEMakeReceptorOptions();
OESimpleAppOptions opts = new OESimpleAppOptions(recOpts, "MakeReceptor", OEFileStringType.DU, OEFileStringType.DU);
if (OEChem.OEConfigureOpts(opts, argv, false) == OEOptsConfigureStatus.Help)
Environment.Exit(1);
recOpts.UpdateValues(opts);
oeifstream ifs = new oeifstream(opts.GetInFile());
oeofstream ofs = new oeofstream(opts.GetOutFile());
OEDesignUnit du = new OEDesignUnit();
OEDesignUnit receptor = new OEDesignUnit();
while (OEBio.OEReadDesignUnit(ifs, du))
{
if (OEDocking.OEMakeReceptor(du, recOpts))
OEBio.OEWriteDesignUnit(ofs, du);
else
OEChem.OEThrow.Fatal(du.GetTitle() + " failed to make a receptor");
}
}
}
Download code
Application with Reference system, Input, output, and Options¶
Besides an input and output, some applications require an additional reference system input. The OERefInputAppOptions class can be used to extend an options class with three additional parameters, an input, output, and a reference system.
The following code example is taken from OEDocking, and uses the OEDock object to perform docking. In this example, the OEDockOptions is extended with an input, output, and a receptor (i.e., the reference system).
Listing 2: Application with input, reference, output, and options (Docking Molecules)
/*
(C) 2022 Cadence Design Systems, Inc. (Cadence)
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED. OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEBio;
using OpenEye.OEDocking;
public class DockMolecules
{
public static void Main(string[] argv)
{
OEDockOptions dockOpts = new OEDockOptions();
OERefInputAppOptions opts = new OERefInputAppOptions(dockOpts, "DockMolecules", OEFileStringType.Mol3D,
OEFileStringType.Mol3D, OEFileStringType.DU, "-receptor");
oemolistream ifs = new oemolistream();
if (!ifs.open(opts.GetInFile()))
OEChem.OEThrow.Fatal("Unable to open " + opts.GetInFile() + " for reading");
oemolostream ofs = new oemolostream();
if (!ofs.open(opts.GetOutFile()))
OEChem.OEThrow.Fatal("Unable to open " + opts.GetOutFile() + " for writing");
oeifstream rfs = new oeifstream();
if (!rfs.open(opts.GetRefFile()))
OEChem.OEThrow.Fatal("Unable to open " + opts.GetRefFile() + " for reading");
OEDesignUnit du = new OEDesignUnit();
if (!OEBio.OEReadDesignUnit(opts.GetRefFile(), du))
OEChem.OEThrow.Fatal("Failed to read design unit ");
if (!du.HasReceptor())
OEChem.OEThrow.Fatal("Design unit " + du.GetTitle() + " does not contain a receptor");
OEDock dock = new OEDock(dockOpts);
dock.Initialize(du);
foreach (OEMol mcmol in ifs.GetOEMols())
{
Console.WriteLine("docking {0}\n", mcmol.GetTitle());
OEGraphMol dockedMol = new OEGraphMol();
uint retCode = dock.DockMultiConformerMolecule(dockedMol, mcmol);
if (retCode != OEDockingReturnCode.Success)
{
OEChem.OEThrow.Error("Docking failed with error code " + OEDocking.OEDockingReturnCodeGetName(retCode));
}
String sdtag = OEDocking.OEDockMethodGetName(dockOpts.GetScoreMethod());
OEDocking.OESetSDScore(dockedMol, dock, sdtag);
dock.AnnotatePose(dockedMol);
OEChem.OEWriteMolecule(ofs, dockedMol);
}
ofs.close();
ifs.close();
}
}
Download code
Application with Input and output only¶
Some applications do not have any additional options or parameters, and only require an input and output. The OESimpleAppOptions class has an overload that does not require an OEOptions input argument.
The following code example is taken from OEQuacpac, and uses
the OEAssignCharges
method to assign charges in
an OEDesignUnit. This example only configures an
input and output, and does not have any additional parameters to configure.
Adding custom parameters¶
Custom parameters can also be added to an application API when a built-in Options class does not contain all required parameters for the application.
The following code example is taken from OEDocking, and uses the OEPosit object to generate pose structures. In this example, the OEPositOptions is extended with an input, output, and receptor (i.e., the reference system). However, the number of poses to generate is not a built-in parameter into the OEPositOptions. This example shows how to add an additional parameter, for the number of poses, to be configured through the command line.
Listing 4: Adding custom parameters (POSIT with Multiple Receptors)
/*
(C) 2022 Cadence Design Systems, Inc. (Cadence)
All rights reserved.
TERMS FOR USE OF SAMPLE CODE The software below ("Sample Code") is
provided to current licensees or subscribers of Cadence products or
SaaS offerings (each a "Customer").
Customer is hereby permitted to use, copy, and modify the Sample Code,
subject to these terms. Cadence claims no rights to Customer's
modifications. Modification of Sample Code is at Customer's sole and
exclusive risk. Sample Code may require Customer to have a then
current license or subscription to the applicable Cadence offering.
THE SAMPLE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED. OPENEYE DISCLAIMS ALL WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. In no event shall Cadence be
liable for any damages or liability in connection with the Sample Code
or its use.
*/
using System;
using OpenEye.OEChem;
using OpenEye.OEBio;
using OpenEye.OEDocking;
public class MyOptions : OEPositOptions
{
public MyOptions() : base()
{
OEUIntParameter param1 = new OEUIntParameter("-numPoses", 1);
param1.AddLegalRange("1", "20");
param1.SetBrief("Number of poses to generate");
_param1 = AddParameter(param1);
}
public uint GetNumPoses()
{
if (_param1.GetHasValue())
return (uint.Parse(_param1.GetStringValue()));
return (uint.Parse(_param1.GetStringDefault()));
}
OEParameter _param1;
}
public class PoseMolecules
{
public static void Main(string[] argv)
{
MyOptions positOpts = new MyOptions();
OERefInputAppOptions opts = new OERefInputAppOptions(positOpts, "PoseMolecules", OEFileStringType.Mol3D,
OEFileStringType.DU, OEFileStringType.DU, "-receptor");
if (OEChem.OEConfigureOpts(opts, argv, false) == OEOptsConfigureStatus.Help)
Environment.Exit(1);
positOpts.UpdateValues(opts);
oemolistream ifs = new oemolistream();
if (!ifs.open(opts.GetInFile()))
OEChem.OEThrow.Fatal("Unable to open " + opts.GetInFile() + " for reading");
oeifstream rfs = new oeifstream();
if (!rfs.open(opts.GetRefFile()))
OEChem.OEThrow.Fatal("Unable to open " + opts.GetRefFile() + " for reading");
oeofstream ofs = new oeofstream();
if (!ofs.open(opts.GetOutFile()))
OEChem.OEThrow.Fatal("Unable to open " + opts.GetOutFile() + " for writing");
OEPosit poser = new OEPosit(positOpts);
OEDesignUnit du = new OEDesignUnit();
uint count = 0;
while (OEBio.OEReadDesignUnit(rfs, du))
{
if (!du.HasReceptor())
OEChem.OEThrow.Fatal("Design unit " + du.GetTitle() + " does not contain a receptor");
poser.AddReceptor(du);
count += 1;
}
if (count == 0)
OEChem.OEThrow.Fatal("Input design unit does not contain any receptor");
OEChem.OEThrow.Info("Number of conformers: " + positOpts.GetNumPoses());
OEChem.OEThrow.Info("Best receptor pose flag: " + positOpts.GetBestReceptorPoseOnly());
foreach (OEMol mcmol in ifs.GetOEMols())
{
OEChem.OEThrow.Info("posing " + mcmol.GetTitle());
OEPositResults results = new OEPositResults();
uint returnCode = poser.Dock(results, mcmol, positOpts.GetNumPoses());
if (returnCode == OEDockingReturnCode.Success)
{
foreach (OESinglePoseResult result in results.GetSinglePoseResults())
{
OEDesignUnit posedDU = new OEDesignUnit(result.GetDesignUnit());
posedDU.SetDoubleData(poser.GetName(), result.GetProbability());
OEChem.OEThrow.Info("Receptor used: " + posedDU.GetTitle() + " pose probability: " + result.GetProbability());
OEBio.OEWriteDesignUnit(ofs, posedDU);
}
}
else
{
string errMsg = OEDocking.OEDockingReturnCodeGetName(returnCode);
OEChem.OEThrow.Warning(mcmol.GetTitle() + " : " + errMsg);
}
}
ofs.close();
ifs.close();
rfs.close();
}
}
Download code
Defining new options class¶
Options classes, derived from OEOptions, can also be defined at the script level, and wrapped with the OESimpleAppOptions or OERefInputAppOptions, to build applications.
The following code example is taken from OEFF, and optimizes molecule conformations using a force field. In this example, a new Options class is defined to accept command line input for the force field.