19package denoptim.fitness;
22import java.io.IOException;
24import java.util.ArrayList;
25import java.util.Arrays;
26import java.util.Enumeration;
27import java.util.HashMap;
31import java.util.TreeSet;
32import java.util.jar.JarEntry;
33import java.util.jar.JarFile;
35import org.openscience.cdk.IImplementationSpecification;
36import org.openscience.cdk.qsar.DescriptorEngine;
37import org.openscience.cdk.qsar.IDescriptor;
39import com.google.common.io.Files;
41import denoptim.exception.DENOPTIMException;
45 private static final String
FS = System.getProperty(
"file.separator");
52 new String[]{
"JPLogP"});
65 String jarFileWildQuery)
67 String pkgPath = packageName.replace(
".",
FS);
68 List<String> jarPathNames =
new ArrayList<String>();
69 String classPath = System.getProperty(
"java.class.path");
70 String[] jarsAndDirs = classPath.split(File.pathSeparator);
71 for (
int i = 0; i < jarsAndDirs.length; i++)
73 String pathName = jarsAndDirs[i];
74 if (!pathName.endsWith(
".jar"))
81 jarFile =
new JarFile(pathName);
82 Enumeration<JarEntry> enumeration = jarFile.entries();
83 while (enumeration.hasMoreElements()) {
84 JarEntry jarEntry = enumeration.nextElement();
86 if (jarEntry.toString().replace(
"/",
FS).replace(
"\\",
FS)
89 jarPathNames.add(pathName);
93 }
catch (IOException e) {
98 List<String> classNames =
new ArrayList<String>();
99 if (jarPathNames.size()>0)
101 for (String jarPathName : jarPathNames)
103 classNames.addAll(DescriptorEngine
104 .getDescriptorClassNameByPackage(packageName,
105 new String[]{jarPathName}));
109 ClassLoader cl =
new ClassLoader() {};
110 Enumeration<URL> roots =
null;
113 roots = cl.getResources(
"");
114 while (roots.hasMoreElements())
116 URL url = roots.nextElement();
117 File root =
new File(url.getPath());
118 for (File f : Files.fileTraverser().breadthFirst(root))
120 if (!f.isDirectory() && f.getPath().contains(pkgPath))
122 String tmp = f.getPath()
123 .substring(f.toString().indexOf(pkgPath))
124 .replace(File.separator,
".")
125 .replace(
".class",
"");
126 if (tmp.indexOf(
'$') != -1)
continue;
127 if (tmp.indexOf(
"Test") != -1)
continue;
128 if (!classNames.contains(tmp)) classNames.add(tmp);
132 }
catch (IOException e)
182 List<String> classNames =
new ArrayList<String>();
202 List<String> classNames =
new ArrayList<String>();
222 List<String> classNames =
new ArrayList<String>();
241 Set<String> requiredDescriptors, List<String> classNames)
245 DescriptorEngine engine =
new DescriptorEngine(classNames,
null);
246 List<IDescriptor> iDescs = engine.instantiateDescriptors(classNames);
248 List<DescriptorForFitness> chosenOnes =
249 new ArrayList<DescriptorForFitness>();
250 Set<String> chosenOnesShortNames =
new TreeSet<String>();
254 Map<String,String> unq =
new HashMap<String,String>();
255 for (
int i=0; i<classNames.size(); i++)
257 String className = classNames.get(i);
258 String[] descrNames = iDescs.get(i).getDescriptorNames();
259 String simpleName = iDescs.get(i).getClass().getSimpleName();
261 if (descrNames !=
null)
263 for (
int j=0; j<descrNames.length;j++)
265 String descName = descrNames[j];
267 if (unq.containsKey(descName))
269 String msg =
"Descriptor '" + descName +
"' in part of "
271 +
" but its name was already used in "
275 unq.put(descName,simpleName);
276 boolean isChosen =
false;
277 if (requiredDescriptors ==
null)
281 for (String requiredDescName : requiredDescriptors)
283 if (descName.equals(requiredDescName))
295 if (descName.equals(rejectedDescName))
304 chosenOnesShortNames.add(simpleName);
305 IDescriptor impl = iDescs.get(i);
306 IImplementationSpecification implSpec =
307 impl.getSpecification();
314 descName, className,impl, j,
320 descName, className,impl, j,
321 engine.getDictionaryClass(implSpec),
322 engine.getDictionaryDefinition(
323 implSpec.getSpecificationReference()),
324 engine.getDictionaryTitle(
325 implSpec.getSpecificationReference()));
This is a reference to a specific descriptor value.
static DescriptorEngine getCDKDescriptorEngine()
Makes an engine using CDK descriptors.
static List< String > getClassNamesToCDKDescriptors()
static List< DescriptorForFitness > findAllCDKDescriptors(Set< String > requiredDescriptors)
Searches for descriptor implementations in the CDK packages.
static List< DescriptorForFitness > findAllDescriptorImplementations(Set< String > requiredDescriptors)
Searches for descriptor implementations.
static List< String > getAllClassNamesInPackage(String packageName, String jarFileWildQuery)
Search for packages in the class path and in the appended archives.
static List< DescriptorForFitness > findAllDENOPTIMDescriptors(Set< String > requiredDescriptors)
Searches for descriptor implementations in the DENOPTIM packages.
static List< String > rejectedDescriptors
List of descriptor names that are excluded from default import because they have been shown to contai...
static List< DescriptorForFitness > findDescriptorImplementations(Set< String > requiredDescriptors, List< String > classNames)
Searches for descriptor implementations.
static List< String > getClassNamesToDenoptimDescriptors()
This interface forces descriptors that are not defined in the CDK ontology to provide information tha...
String[] getDictionaryClass()
Get the classification of this descriptor.
String getDictionaryTitle()
Gets the title of this descriptor as it should be in the dictionary.
String getDictionaryDefinition()
Get a string that describes the descriptor in detail.