Hi Gilleain,

Thanks for those ideas! However, I think that both approaches, i.e. "adding
the wanted atoms" vs. "removing the unwanted atoms" (see code below), have
some issues attached to it:

If you start with a clean AtomContainer, the properties of the original
atomContainer (e.g. SingleElectron objects ) will not be preserved in the
new substructure.
If you start by cloning the original AtomContainer, and remove all the
unwanted atoms and bonds, you will encounter numbering problems: after you
have removed one atom/bond, the resulting substructure will be renumbered
and has thus new atom/bond indices. The removal of the next atom/bond based
on the original array of atomIndices might be impossible since that atom
index is no longer in use in the new substructure...

Do you agree with me?

Nick



public static IAtomContainer extract(IAtomContainer atomContainer, int[]
atomIndices) throws CloneNotSupportedException { 
                IAtomContainer substructure = (IAtomContainer)
atomContainer.clone();
                
                Arrays.sort(atomIndices);
                
                for (IBond bond : atomContainer.bonds()) { 
                        int bondNo = atomContainer.getBondNumber(bond);
                        int atom0 =
atomContainer.getAtomNumber(bond.getAtom(0)); 
                        int atom1 =
atomContainer.getAtomNumber(bond.getAtom(1));
                        if (Arrays.binarySearch(atomIndices, atom0) > -1 ||
Arrays.binarySearch(atomIndices, atom1) > -1) { 
                                substructure.removeBond(bondNo); 
                        }
                }
                
                for(IAtom atom : atomContainer.atoms()){
                        int atomNo = atomContainer.getAtomNumber(atom);
                        if (Arrays.binarySearch(atomIndices,atomNo) > -1){
                                substructure.removeAtom(atomNo);
                        }
                        
                }
                
                return substructure;
}

-----Original Message-----
From: gilleain torrance [mailto:gilleain.torra...@gmail.com] 
Sent: Tuesday, January 11, 2011 4:57 PM
To: Developers forum for discussion about the Chemistry Development Kit
(CDK); nick.vandewi...@ugent.be
Subject: Re: [Cdk-user] extract substructure from molecule by specifying the
atom numbers?

Hi,

I don't know of any simple way to do this, but it would make a nice
utility method or class. For example:

public class SubstructureExtractor {

public static IAtomContainer extract(IAtomContainer atomContainer,
int... atomIndices) {
IAtomContainer substructure =
atomContainer.getBuilder().newInstance(IAtomContainer.class);
for (int atomIndex : atomIndices) {
substructure.addAtom(atomContainer.getAtomAt(atomIndex));  // may not
be correct method - I forget
}
Arrays.sort(atomIndices); // necessary for searching
for (IBond bond : atomContainer.bonds()) {
int atom0 = bond.getAtom(0);
int atom1 = bond.getAtom(1);
if (Arrays.binarySearch(atomIndices, atom0) > -1 &&
Arrays.binarySearch(atomIndices, atom1) > -1) {
substructure.addBond(bond);
}
return substructure;
}}

Note that I haven't run this through a compiler, so it might not work!
But the basics are there. Oh, and it might be better to clone the
original atom container, and then remove those atoms that are not in
the list as well as bonds that have less than both atoms in the list.

gilleain



On Tue, Jan 11, 2011 at 3:06 PM, Nick Vandewiele
<nick.vandewi...@ugent.be> wrote:
> Hi,
>
>
>
> I have been given a molecule in which a substructure was defined by the
atom
> numbers of the original molecule. E.g. substructure made up of atoms no.
[0,
> 1, 2, 3, 4] of the original molecule. Is there any way in CDK to extract
> this substructure and produce a new molecule from the original molecule?
>
>
>
> Probably this could be done in a very elegant way, but I haven’t found any
> functionality in CDK that performs this operation…
>
>
>
> Thanks in advance,
>
>
>
> Nick
>
>
>
>
----------------------------------------------------------------------------
--
> Gaining the trust of online customers is vital for the success of any
> company
> that requires sensitive data to be transmitted over the Web.   Learn how
to
> best implement a security strategy that keeps consumers' information
secure
> and instills the confidence they need to proceed with transactions.
> http://p.sf.net/sfu/oracle-sfdevnl
> _______________________________________________
> Cdk-user mailing list
> Cdk-user@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/cdk-user
>
>


------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Cdk-user mailing list
Cdk-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cdk-user

Reply via email to