/* (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. */ /**************************************************************************** * Extracting rings/ring systems from input molecules ****************************************************************************/ using System; using OpenEye.OEChem; public class RingSubset { public static void Main(string[] args) { OEInterface itf = new OEInterface(interfaceData, "RingSubset", args); bool exo_dbl_bonds = itf.GetBool("-exo"); oemolistream ifs = new oemolistream(); if (!ifs.open(itf.GetString("-i"))) { OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-i") + " for reading"); } oemolostream ofs = new oemolostream(".ism"); if (itf.HasString("-o")) { if (!ofs.open(itf.GetString("-o"))) { OEChem.OEThrow.Fatal("Unable to open " + itf.GetString("-o") + " for writing"); } } RingSubSet(ifs, ofs, exo_dbl_bonds); } private static void RingSubSet(oemolistream ifs, oemolostream ofs, bool exo) { OEGraphMol mol = new OEGraphMol(); while (OEChem.OEReadMolecule(ifs, mol)) { OEGraphMol submol = new OEGraphMol(); OEUnaryAtomPred pred = new OEAtomIsInRing(); if (exo) { pred = new OEOrAtom(pred, new OEIsNonRingAtomDoubleBondedToRing()); } bool adjustHCount = true; OEChem.OESubsetMol(submol, mol, pred, adjustHCount); string title = mol.GetTitle() + "_rings"; submol.SetTitle(title); if (submol.NumAtoms() != 0) { OEChem.OEWriteMolecule(ofs, submol); } } } private static string interfaceData=@" !BRIEF [-exo] [-i] [[-o] ] !PARAMETER -i !ALIAS -in !TYPE string !REQUIRED true !BRIEF input file name !KEYLESS 1 !END !PARAMETER -o !ALIAS -out !TYPE string !REQUIRED false !BRIEF output file name !KEYLESS 2 !END !PARAMETER -exo !TYPE bool !DEFAULT true !BRIEF Include non-ring atoms double bonded to a ring !END "; }