Skip to content

Instantly share code, notes, and snippets.

View egonw's full-sized avatar
💭
I don't want a status.

Egon Willighagen egonw

💭
I don't want a status.
View GitHub Profile
// will load a Gist from http://gist.github.com/
// Gist 47981 actually is this JavaScript
gist.load(47981, "/Virtual/gist.47981.js")
// and open it in a JavaScript editor
ui.open("/Virtual/gist.47981.js")
// Bioclipse variant of SMILES Depict
var smiles = "CC=O"
var aceticAcid = cdk.fromSMILES(smiles)
aceticAcid = cdk.generate2dCoordinates(aceticAcid)
cdk.saveMDLMolfile(aceticAcid, "/Virtual/aceticAcid.mol")
ui.open("/Virtual/aceticAcid.mol") // should open JChemPaint
// debug CDK atom types starting from SMILES
var smiles = "[nH0]1c([nH0]cc1[N+](=O)[O-])"
var file = "/Virtual/smiles5.mol"
var mol = cdk.fromSMILES(smiles)
mol = cdk.generate2dCoordinates(mol)
cdk.saveMDLMolfile(mol, file)
cdx.perceiveCDKAtomTypes(mol)
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbpedia: <http://dbpedia.org/ontology/>
PREFIX dbprop: <http://dbpedia.org/property/>
SELECT DISTINCT ?compound ?smiles WHERE {
?compound a dbpedia:ChemicalCompound .
?compound dbprop:section ?section .
?section dbprop:smiles ?smiles .
} ORDER BY ?compound LIMIT 1000 OFFSET 0
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbpedia: <http://dbpedia.org/ontology/>
PREFIX dbprop: <http://dbpedia.org/property/>
SELECT DISTINCT ?compound ?inchi WHERE {
?compound a dbpedia:ChemicalCompound .
?compound dbprop:section ?section .
?section dbprop:inchi ?inchi .
} ORDER BY ?compound LIMIT 1000 OFFSET 0
// script that shows how the CDK parses SMILES
mol1 = cdk.fromSMILES("C")
mol2 = cdk.fromSMILES("[13C]")
cdx.diff(mol1, mol2)
// output:
// AtomContainerDiff{AtomDiff{H:4/0, AtomTypeDiff{IsotopeDiff{MN:NA/13}}}}
# SPARQL listing all ONS Measurements
PREFIX ons: <http://spreadsheet.google.com/plwwufp30hfq0udnEmRD1aQ/onto#>
SELECT DISTINCT
?s
WHERE {
?s a ons:Measurement
}
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX dbpedia: <http://dbpedia.org/ontology/>
PREFIX dbprop: <http://dbpedia.org/property/>
SELECT DISTINCT ?compound ?smiles WHERE {
?compound a dbpedia:Drug .
?compound dbprop:smiles ?smiles
} ORDER BY ?compound LIMIT 1000 OFFSET 0
// search and download entries from PubChem
var query = "aspirin";
var searchResults = pubchem.search(query);
var max = Math.min(15, searchResults.size());
for (i=0; i<max; i++) {
var cid = searchResults.get(i);
var filename = "/Virtual/" + query.replace(" ", "") + "." + cid + ".xml";
var filename3d = "/Virtual/" + query.replace(" ", "") + "." + cid + ".mol";
js.print("downloading CID " + cid + "...\n");
// download and process the ONS Solubility RDF data
ons = rdf.createStore()
rdf.importURL(ons,"http://github.com/egonw/onssolubility/raw/master/ons.solubility.rdf/ons.rdf")
rdf.sparql(ons,"SELECT DISTINCT ?type WHERE { ?s a ?type }")
// or, list all solutes:
rdf.sparql(ons,"SELECT ?s WHERE { ?s a <http://spreadsheet.google.com/plwwufp30hfq0udnEmRD1aQ/onto#Solute> }")
// or, just dump the whole database to the console
rdf.dump(ons)