User 2347372188
16-11-2011 00:24:36
It appears that constructor for CFGenerator has been changed. CFGenerator(int) not longer works. In addition, the default constructor CFGenerator() doesn't work either. How is the CFGenerator class supposed to be used in version 5.7.0? Thanks.
-&
ChemAxon 4a2fc68cd1
16-11-2011 23:15:18
Hi Steven,
As far as I know, CFGenerator was not modified recently. CFGenerator(int) constructor should work in JChem 5.7 though it has been deprecated. Unfortunately, we forgot to add a default constructor when we deprecated this one. The upcoming releases will fix this bug.
Could you clarify what kind of problems did you encounter? Only warnings about deprecation? Or the code does not compile? Or does it operate differently than it should be?
Anyway, it is better to avoid the direct usage of the generators. You can generate CF descriptors like that:
CFParameters params = new CFParameters();
... // set parameters
ChemicalFingerprint cfp = new ChemicalFingerprint(params);
cfp.generate(mol);
Or you can use the DescriptorGenerator API.
Best regards,
Peter
User 2347372188
17-11-2011 17:27:25
Hi Peter. My problem is that I'm getting NullPointerException in code that used to work just fine (it's old-ish code and I don't remember in which version of JChem it used to work). This is what I'm doing:
CFParameters cfp = new CFParameters();
cfp.setLength(1024);
cfp.setBondCount(6);
cfp.setBitCount(2);
CFGenerator cfg = new CFGenerator(1024);
ChemicalFingerprint cf = new ChemicalFingerprint(cfp);
String smi = "c1ccnc1CNC";
log.debug("processing smiles: " + smi);
MolHandler mh = new MolHandler(smi);
Molecule m = mh.getMolecule();
if (m == null) {
log.error("m == null");
}
if (!m.hasValenceError()) {
String[] fp = cfg.generate(m,cf);
}
This code always yields a null fingerprint (i.e., fp == null). Can you tell me what I'm doing wrong? Thanks.
-&
ChemAxon 4a2fc68cd1
18-11-2011 08:04:31
Hi Steven,
I see now. The generate() function of fingerprint generators could be misleading. They do not return the generated fingerprint, they could return some additional information. In case of CFGenerator, the return value is always null (it hasn't been changed since 2004). However, the fingerprint is generated in the cf object.
The simplest way to fix your code is to replace this line:
String[] fp = cfg.generate(m,cf);
with this code:
cfg.generate(m,cf);
String fp = cf.toBinaryString();
However, I suggest you the usage of DescriptorGenerator.
DescriptorGenerator gen = new DescriptorGenerator("CF");
gen.setParameter("Length", "1024");
gen.setParameter("BondCount", "6");
gen.setParameter("BitCount", "2");
String smi = "c1ccnc1CNC";
log.debug("processing smiles: " + smi);
MolHandler mh = new MolHandler(smi);
Molecule m = mh.getMolecule();
if (m == null) {
log.error("m == null");
}
if (!m.hasValenceError()) {
// generate the fingerprint
gen.generate(mol);
// get fp as a string
String fp = gen.getAsString();
// or get fp as a bit set:
// BitSet fp = gen.getAsBitSet();
}
Best regards,
Peter