Showing posts with label chemistry. Show all posts
Showing posts with label chemistry. Show all posts

24 September 2009

XSLT+Pubchem Reloaded : XSLT+Pubchem = Processing



In a Previous post I've show how XSLT can be used to transform a NCBI/Pubchem entry into a SVG figure. Here, I've sightly modified the original stylesheet to produce a script for Processing generating a 3D model.
From processing.org: Processing is an open source programming language and environment for people who want to program images, animation, and interactions. (...) It is created to teach fundamentals of computer programming within a visual context and to serve as a software sketchbook and professional production tool. Processing is an alternative to proprietary software tools in the same domain..

The new XSLT stylesheet is available here:

Here the XML record of the Lysergic Acid Diethylamide was transformed with pubchem2processing.xsl and the resulted document was uploaded on www.openprocessing.org.


http://www.openprocessing.org/visuals/?visualID=4768

Keys:
'a','z' : +/- opacity
'q','s': +/- zoom
'w','x': +/- atom


The script

//number of atoms
static final int ATOM_COUNT=49;

//array of X positions
static final float array_x[]=new float[]{-1.0624f,-0.1926f,2.4616f,-2.9068f,0.621f,-0.0035f,0.8984f,-1.5992f,-0.6594f,1.4746f,0.5697f,1.2663f,-1.0406f,1.88f,0.5459f,-1.8248f,2.2196f,0.5148f,1.8335f,1.1364f,-3.7848f,-3.2395f,-4.9351f,-2.5399f,1.5948f,1.5945f,-0.0372f,-2.5309f,-1.1865f,0.1964f,-1.5165f,-0.066f,1.4755f,0.7855f,2.5985f,-0.0002f,2.9867f,2.312f,1.0802f,-4.1574f,-3.2447f,-4.3255f,-2.9262f,-5.5678f,-4.6148f,-5.5631f,-2.7809f,-1.4522f,-2.8311};

//array of Y positions
static final float array_y[]=new float[]{1.9255f,-2.0756f,-4.5862f,1.6411f,-2.2073f,-1.4656f,-3.7309f,-0.2934f,-0.693f,-3.9266f,-1.7401f,-2.9517f,-0.6232f,-3.3703f,-2.4961f,1.1879f,-4.9333f,-0.9572f,-2.6029f,-1.3866f,0.7312f,3.0553f,0.2896f,3.6858f,-1.7188f,-4.1373f,-4.301f,-0.8592f,-0.5986f,-0.0044f,-0.1663f,-2.3585f,-1.9308f,-3.5629f,-5.864f,-0.0001f,-5.1463f,-2.9253f,-0.7582f,1.2483f,-0.137f,3.1734f,3.5585f,-0.4132f,-0.2018f,1.1385f,4.7518f,3.5919f,3.221};

//array of Z positions
static final float array_z[]=new float[]{3.398f,4.9603f,0.2014f,4.7838f,3.7188f,2.4987f,3.4375f,3.9986f,5.1388f,2.0807f,1.162f,1.0834f,2.6488f,-0.0856f,6.1555f,4.0282f,1.5131f,0.0024f,-1.2504f,-1.179f,5.5151f,4.8984f,4.6696f,6.0586f,3.8837f,4.1797f,3.5062f,4.0616f,6.0948f,5.1994f,1.7844f,7.0548f,6.2861f,6.1251f,1.9113f,0.0001f,-0.4557f,-2.1682f,-2.0652f,6.4075f,5.8928f,4.9775f,3.9766f,5.2214f,3.7461f,4.3781f,6.1202f,5.9687f,7.0063};

//array of atom names
static final char array_c[]=new char[]{'o','n','n','n','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h','h'};

//number of bounds
static final int BOUND_COUNT=52;

//bound start index
static final int bound_start[]=new int[]{0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,6,6,6,7,7,7,7,8,8,9,9,10,10,11,12,13,14,14,14,16,17,17,18,18,19,20,20,20,21,21,21,22,22,22,23,23,23};

//bound end index
static final int bound_end[]=new int[]{15,4,8,14,13,16,36,15,20,21,5,6,24,10,12,9,25,26,8,12,15,27,28,29,11,16,11,17,13,30,18,31,32,33,34,19,35,19,37,38,22,39,40,23,41,42,43,44,45,46,47,48};

//Name of this product
static final String title= "3981";


float mid_x=0f;
float mid_y=0f;
float mid_z=0f;
float alpha=150;
float zoom=10f;
float zoomAtom=1.0f;

void setup()
{

size(
500,
500,
P3D);
mid_x= center(array_x);
mid_y= center(array_y);
mid_z= center(array_z);
}

void draw()
{
lights();
background(0);

translate(width / 2, height / 2,0);
rotateY(map(mouseX, 0, width, 0, TWO_PI));
rotateZ(map(mouseY, 0, height, 0, -TWO_PI));
stroke(170, 0, 0);
for(int i=0; i< BOUND_COUNT;++i)
{
line(
xAngstrom(array_x[bound_start[i]] -mid_x ),
xAngstrom(array_y[bound_start[i]] -mid_y),
xAngstrom(array_z[bound_start[i]] -mid_z),
xAngstrom(array_x[bound_end[i]] -mid_x ),
xAngstrom(array_y[bound_end[i]] -mid_y ),
xAngstrom(array_z[bound_end[i]] -mid_z )
);
}
noStroke();
for(int i=0;i < ATOM_COUNT;++i)
{
pushMatrix();
translate(
xAngstrom(array_x[i] -mid_x ),
xAngstrom(array_y[i] -mid_y ),
xAngstrom(array_z[i] -mid_z )
);
fillAtom(array_c[i]);
sphere(zoomAtom*radiusOf(array_c[i]));
popMatrix();
}

}

float xAngstrom(float x)
{
return x*zoom;
}

int radiusOf(char c)
{
switch(c)
{
case 'o':case 'O': return 14;
case 'c':case 'C': return 12;
case 'h':case 'H': return 6;
default: return 10;
}
}

void fillAtom(char c)
{
switch(c)
{
case 'o':case 'O': fill(0,0,200,alpha); break;
case 'c':case 'C': fill(100,100,100,alpha); break;
case 'h':case 'H': fill(200,200,200,alpha); break;
case 'n':case 'N': fill(142,142,0,alpha); break;
case 's':case 'S': fill(142,0,142,alpha); break;
default: fill(142,142,142,alpha);break;
}
}

static float center(final float array[])
{
float t=0f;
for(int i=0;i< array.length;++i)
{
t+=array[i];
}
return t/float(array.length);
}

void keyPressed()
{
final float alphaShift=5;
final float zoomShift=0.5;
final float zoomAtomShift=0.1;
switch(key)
{
case 'a':case 'A': if(alpha-alphaShift >=0) this.alpha-=alphaShift; break;
case 'z':case 'Z': if(alpha+alphaShift <=255) this.alpha+=alphaShift; break;
case 'q':case 'Q': zoom+=zoomShift; break;
case 's':case 'S': if(zoom-zoomShift>0) zoom-=zoomShift; break;
case 'w':case 'W': zoomAtom+=zoomAtomShift; break;
case 'x':case 'X': if(zoomAtom-zoomAtomShift >0) zoomAtom-=zoomAtomShift; break;
default:break;
}
}


That's it
Pierre

04 June 2009

Fun with SVG: NCBI/pubchem+XSLT= SVG

Just for fun. I've played with the compounds stored in NCBI/Pubchem and I've created a XSLT stylesheet transforming the pubchem/xml format into a SVG figure.
The XSLT stylesheet is available here:

This xml format was new to me, so feel free to tell me if I've missed something...

Here are two examples:
The stylesheet takes a few optional arguments:
  • scale :=scale factor
  • show-bounds := (true/false)
  • xradius := scale factor for atoms

Example


xsltproc --stringparam scale 30 --stringparam xradius 2 --stringparam show-bounds false src/xsl/pubchem2svg.xsl CID_16204538.xml > file.svg


A few points about how it works


First we need to collect the min/max values of each x/y/z coordinate. For example for max-x, we get an ordered list of all the X coordinates and we get the first item.
<xsl:variable name="max-x">
<xsl:for-each select="$x_array/c:PC-Conformer_x_E">
<xsl:sort select="." data-type="number" order="descending"/>
<xsl:if test="position() = 1">
<xsl:value-of select="."/>
</xsl:if>
</xsl:for-each>
</xsl:variable>


Then we loop over the index for each atom and we call the template xyz
<xsl:comment>BEGIN ATOMS</xsl:comment>
<xsl:element name="svg:g">
<xsl:call-template name="xyz">
<xsl:with-param name="index" select="1"/>
</xsl:call-template>
</xsl:element>
<xsl:comment>END ATOMS</xsl:comment>
</xsl:element>

For each index-th atom, the template xyz create a SVG figure for the atom. A call to the templates coord-x and coord-y returns the coordinates (x/y) of this element on the SVG panel.
<xsl:element name="svg:use">
<xsl:attribute name="xlink:href">#atom<xsl:choose>
<xsl:when test="$s='o' or $s='c' or $s='h'"><xsl:value-of select="$s"/></xsl:when>
<xsl:otherwise>UN</xsl:otherwise>
</xsl:choose></xsl:attribute>
<xsl:attribute name="x"><xsl:call-template name="coord-x"><xsl:with-param name="index" select="$index"/></xsl:call-template></xsl:attribute>
<xsl:attribute name="y"><xsl:call-template name="coord-y"><xsl:with-param name="index" select="$index"/></xsl:call-template></xsl:attribute>
<xsl:attribute name="title"><xsl:value-of select="$s"/><xsl:text> </xsl:text><xsl:value-of select="$index"/></xsl:attribute>
</xsl:element>

The template coord-x itself align the coordinate of the atom according to the scale and the width of the SVG panel:
<xsl:template name="coord-x">
<xsl:param name="index"/>
<xsl:variable name="x" select="$x_array/c:PC-Conformer_x_E[$index]"/>
<xsl:value-of select="$margin + ($x - $min-x) * $scale"/>
</xsl:template>


That's it.

Pierre

PS: See also the post I wrote one year ago NCBI Blast+ XSLT => XHTML + SVG .

22 November 2008

A Web Service for ONSolubility.

This post is about the ONSolubility project (For references search FriendFeed for Solubility). This post is about how I've used Egon's code to create a web service to query the data of solubility. Egon has already done a great job by using the google java spreasheet API to download Jean-Claude's Solubility data. On his side, Rajarshi Guha wrote an HTML page querying those data using the Google Query-API. Here I show how I have created a webservice searching for the measurements based on their solvent/solute/concentration.

Server Side


Classes


I've added some JAXB(Java Architecture for XML Binding) annotations to Egon's Measurement.java. Those annotations help the web-service compiler (wsgen) to understand how the data will be transmitted to the client.
@javax.xml.bind.annotation .XmlRootElement(name="Measurement")
public class Measurement
implements Serializable
{
(...)

Then we create the WebService ONService.java. This service is just a java class containing also a few annotations. First we flag the class as a webservice:
@javax.jws.WebService(
name="onsolubility",
serviceName="ons"
)
public class ONService
{
Then comes the function seach provided by this service. This function will download the data from google using Egon's API and will return a collection of Measurement based on their solute/solvent/concentration. Again the java annotations will help the compiler to implement the service
@WebMethod(action="urn:search",operationName="search")
public List search(
@WebParam(name="solute")String solute,
@WebParam(name="solvent")String solvent,
@WebParam(name="concMin")Double concMin,
@WebParam(name="concMax")Double concMax
) throws Exception
{....
. The web service is launched with only 3 lines of code (!).
ONService service=new ONService();
Endpoint endpoint = Endpoint.create(service);
endpoint.publish("http://localhost:8080/onsolubility");

Compilation


I've create a ant file invoking wsgen generating the stubs and installing the webservice. Here is the ouput
compile-webservice:
[javac] Compiling 1 source file to /home/pierre/tmp/onssolubility/ons.solubility.data/bin
[wsgen] command line: wsgen -classpath (...) -verbose ons.solubility.ws.ONService
[wsgen] Note: ap round: 1
[wsgen] [ProcessedMethods Class: ons.solubility.ws.ONService]
[wsgen] [should process method: search hasWebMethods: true ]
[wsgen] [endpointReferencesInterface: false]
[wsgen] [declaring class has WebSevice: true]
[wsgen] [returning: true]
[wsgen] [WrapperGen - method: search(java.lang.String,java.lang.String,java.lang.Double,java.lang.Double)]
[wsgen] [method.getDeclaringType(): ons.solubility.ws.ONService]
[wsgen] [requestWrapper: ons.solubility.ws.jaxws.Search]
[wsgen] [should process method: main hasWebMethods: true ]
[wsgen] [webMethod == null]
[wsgen] [ProcessedMethods Class: java.lang.Object]
[wsgen] ons/solubility/ws/jaxws/ExceptionBean.java
[wsgen] ons/solubility/ws/jaxws/Search.java
[wsgen] ons/solubility/ws/jaxws/SearchResponse.java
[wsgen] Note: ap round: 2

publish-webservice:
[java] Publishing Service on http://localhost:8080/onsolubility?WSDL
.
And... that's it. When I open my browser on http://localhost:8080/onsolubility?WSDL , I can now see the WSDL description/schema of this service.

Client Side


Writing a client using this api looks the same way I did for a previous post about the IntAct/EBI API where the wsimport command generated the stubs from the WSDL file. I then wrote a simple test ONServiceTest.java, invoking our service several times.
private void test(
String solute,
String solvent,
Double concMin,
Double concMax)
{
try
{
Ons service=new Ons();
Onsolubility port=service.getOnsolubilityPort();
List data=port.search(solute, solvent, concMin, concMax);

for(Measurement measure:data)
{
System.out.println(
" sample :\t"+measure.getSample()+"\n"+
" solute :\t"+measure.getSolute()+"\n"+
" solvent :\t"+measure.getSolvent()+"\n"+
" experiment:\t"+measure.getExperiment()+"\n"+
" reference :\t"+measure.getReference()+"\n"+
" conc :\t"+measure.getConcentration()+"\n"
);
}
} catch(Throwable err)

{
System.err.println("#error:"+err.getMessage());
}
}
private void test()
{
test(null,null,null,null);
test("4-nitrobenzaldehyde",null,null,null);
test("4-nitrobenzaldehyde",null,0.3,0.4);
}
Here is the output
ant test-webservice
Buildfile: build.xml
test-webservice
[wsimport] parsing WSDL...
[wsimport] generating code...
[javac] Compiling 1 source file to onssolubility/ons.solubility.data/bin
[java] ##Searching solute: null solvent: null conc: null-null
[java] sample : 9
[java] solute : D-Glucose
[java] solvent : THF
[java] experiment: 1
[java] reference : http://onschallenge.wikispaces.com/JennyHale-1
[java] conc : 0.00222
[java]
[java] sample : 6
[java] solute : D-Mannitol
[java] solvent : Methanol
[java] experiment: 1
[java] reference : http://onschallenge.wikispaces.com/JennyHale-1
[java] conc : 0.00548
[java]
(...)
[java]
[java] sample : 10
[java] solute : D-Mannitol
[java] solvent : THF
[java] experiment: 1
[java] reference : http://onschallenge.wikispaces.com/JennyHale-1
[java] conc : 0.01098
[java] ##Searching solute: 4-nitrobenzaldehyde solvent: null conc: 0.3-0.4
[java] sample : 2b
[java] solute : 4-nitrobenzaldehyde
[java] solvent : Methanol
[java] experiment: 212
[java] reference : http://usefulchem.wikispaces.com/exp212
[java] conc : 0.38

That's it and that's enough code for the week-end.

Pierre

11 November 2008

SPARQL for solubility/RDF: my notebook

In a recent thread on FriendFeed , I've transformed Jean-Claude's Bradley's data about the solubility of some compounds into RDF.


The original data set looks like this:

The RDF version looks like this:
<!DOCTYPE rdf:RDF [
<!ENTITY rdf "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!ENTITY rdfs "http://www.w3.org/2000/01/rdf-schema#">
<!ENTITY doap "http://usefulinc.com/ns/doap#">
<!ENTITY foaf "http://xmlns.com/foaf/0.1/">
<!ENTITY dc "http://purl.org/dc/elements/1.1/">
<!ENTITY chem "http://blueobelisk.sourceforge.net/chemistryblogs/">
]>
<rdf:RDF
xmlns:rdf="&rdf;"
xmlns:dc="&dc;"
xmlns:rdfs="&rdfs;"
xmlns:doap="&doap;"
xmlns:foaf="&foaf;"
xmlns:chem="&chem;"
>
<!--=== PERSONS ============================================================== -->
<foaf:Person rdf:about="http://www.chemistry.drexel.edu/people/bradley/bradley.asp">
<foaf:name>Jean-Claude Bradley</foaf:name>
<foaf:nick>jcbradley</foaf:nick>
<foaf:sha1_sum>b68f7dca9555a1cfe1ad18c6d2be0db6e552d678</foaf:sha1_sum>
<foaf:holdsAccount>
<foaf:OnlineAccount>
<foaf:accountServiceHomepage rdf:resource="http://www.linkedin.com/"/>
<foaf:accountProfilePage rdf:resource="http://www.linkedin.com/in/jcbradley"/>
</foaf:OnlineAccount>
</foaf:holdsAccount>
</foaf:Person>

<!--=== PROJECT ============================================================== -->
<doap:Project rdf:ID="SolubilityProject">
<doap:name>Solubility</doap:name>
<doap:homepage rdf:resource="http://spreadsheets.google.com/ccc?key=plwwufp30hfq0udnEmRD1aQ" />
<doap:shortdesc xml:lang="en">Solubility</doap:shortdesc>
<doap:shortdesc xml:lang="fr">Solubilité</doap:shortdesc>
<doap:description xml:lang="en">Solubility</doap:description>
<doap:description xml:lang="fr">Solubilité</doap:description>
</doap:Project>
<!--=== Compound ============================================================== -->

<chem:Compound rdf:about="http://commons.wikimedia.org/wiki/Image:D-Mannitol_structure.png">
<chem:name>D-Manitol</chem:name>
<chem:image rdf:resource="http://upload.wikimedia.org/wikipedia/commons/b/bb/D-Mannitol_structure.png"/>
<chem:smiles>O[C@H]([C@H](O)CO)[C@H](O)[C@H](O)CO</chem:smiles>
</chem:Compound>

<chem:Compound rdf:about="http://en.wikipedia.org/wiki/Ethanol">
<chem:name>Ethanol</chem:name>
<chem:image rdf:resource="http://upload.wikimedia.org/wikipedia/commons/6/6f/Ethanol_flat_structure.png"/>
<chem:smiles>OCC</chem:smiles>
</chem:Compound>

<chem:Compound rdf:about="http://en.wikipedia.org/wiki/Sodium_chloride">
<chem:name>Sodium chloride</chem:name>
<chem:image rdf:resource="http://upload.wikimedia.org/wikipedia/commons/e/e9/Sodium-chloride-3D-ionic.png"/>
<chem:smiles>[Na+].[Cl-]</chem:smiles>
</chem:Compound>

<!--=== Experiment ============================================================== -->
<chem:Experiment rdf:about="http://usefulchem.wikispaces.com/exp207">
<dc:name>Hello, I'm Experiment 207</dc:name>
<chem:project rdf:resource="#SolubilityProject"/>
</chem:Experiment>

<chem:Experiment rdf:about="http://usefulchem.wikispaces.com/exp1">
<dc:name>Hello, I'm Experiment 1</dc:name>
<chem:project rdf:resource="#SolubilityProject"/>
</chem:Experiment>

<!--=== Sample ============================================================== -->
<chem:Sample rdf:about="sample:11">
<dc:name>Hello, I'm Sample 11</dc:name>
</chem:Sample>
<chem:Sample rdf:about="sample:3">
<dc:name>Hello, I'm Sample 3</dc:name>
</chem:Sample>
<chem:Sample rdf:about="sample:12">
<dc:name>Hello, I'm Sample 12</dc:name>
</chem:Sample>
<!--=== Experimental Data ============================================================== -->
<chem:ExperimentalData >
<dc:date>2008-01-01</dc:date>
<chem:author rdf:resource="http://www.chemistry.drexel.edu/people/bradley/bradley.asp"/>
<chem:solute rdf:resource="http://commons.wikimedia.org/wiki/Image:D-Mannitol_structure.png"/>
<chem:solvent rdf:resource="http://en.wikipedia.org/wiki/Ethanol"/>
<chem:experiment-id rdf:resource="http://usefulchem.wikispaces.com/exp207"/>
<chem:sample rdf:resource="sample:11"/>
<chem:concentration rdf:datatype="chem:Molar">0.00</chem:concentration>
</chem:ExperimentalData>

<chem:ExperimentalData>
<dc:date>2008-02-01</dc:date>
<chem:author rdf:resource="http://www.chemistry.drexel.edu/people/bradley/bradley.asp"/>
<chem:solute rdf:resource="http://en.wikipedia.org/wiki/Sodium_chloride"/>
<chem:solvent rdf:resource="http://en.wikipedia.org/wiki/Ethanol"/>
<chem:experiment-id rdf:resource="http://onschallenge.wikispaces.com/JennyHale-1"/>
<chem:sample rdf:resource="sample:3"/>
<chem:concentration rdf:datatype="chem:Molar">0.00</chem:concentration>
</chem:ExperimentalData>

<chem:ExperimentalData>
<dc:date>2008-03-01</dc:date>
<chem:author rdf:resource="http://www.chemistry.drexel.edu/people/bradley/bradley.asp"/>
<chem:solute rdf:resource="http://en.wikipedia.org/wiki/Sodium_chloride"/>
<chem:solvent rdf:resource="http://en.wikipedia.org/wiki/Ethanol"/>
<chem:experiment-id rdf:resource="http://usefulchem.wikispaces.com/exp207"/>
<chem:sample rdf:resource="sample:12"/>
<chem:concentration rdf:datatype="chem:Molar">0.00</chem:concentration>
</chem:ExperimentalData>

</rdf:RDF>

Here I describe how I used SPARQL to retrieve Jean-Claude's original data set from this RDF file.
I've downloaded ARQ , the SPARQL engine, from http://jena.sourceforge.net/ARQ/.
Here are a few queries:

listing all the chem:Compound


query


PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX doap: <http://usefulinc.com/ns/doap#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX chem: <http://blueobelisk.sourceforge.net/chemistryblogs/>

SELECT ?x
{
?x
}

Running the query


sparql -query jeter.rq --data=solubility.rdf

Result


----------------------------------------------------------------------
| x |
======================================================================
| <http://en.wikipedia.org/wiki/Sodium_chloride> |
| <http://en.wikipedia.org/wiki/Ethanol> |
| <http://commons.wikimedia.org/wiki/Image:D-Mannitol_structure.png> |
----------------------------------------------------------------------

The same query but using prefixes


query


PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX doap: <http://usefulinc.com/ns/doap#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX chem: <http://blueobelisk.sourceforge.net/chemistryblogs/>

SELECT ?x
{
?x rdf:type chem:Compound
}

result


----------------------------------------------------------------------
| x |
======================================================================
| <http://en.wikipedia.org/wiki/Sodium_chloride> |
| <http://en.wikipedia.org/wiki/Ethanol> |
| <http://commons.wikimedia.org/wiki/Image:D-Mannitol_structure.png> |
----------------------------------------------------------------------

Listing the compounds , their names, their 'smiles'


query


PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX doap: <http://usefulinc.com/ns/doap#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX chem: <http://blueobelisk.sourceforge.net/chemistryblogs/>

SELECT ?compound ?compoundName ?compoundSmiles
{
?compound rdf:type chem:Compound .
?compound chem:name ?compoundName .
?compound chem:smiles ?compoundSmiles .
}

result


-----------------------------------------------------------------------------------------------------------------------------------
| compound | compoundName | compoundSmiles |
===================================================================================================================================
| <http://en.wikipedia.org/wiki/Sodium_chloride> | "Sodium chloride" | "[Na+].[Cl-]" |
| <http://en.wikipedia.org/wiki/Ethanol> | "Ethanol" | "OCC" |
| | "D-Manitol" | "O[C@H]([C@H](O)CO)[C@H](O)[C@H](O)CO" |
-----------------------------------------------------------------------------------------------------------------------------------

The same, but only the compounds with a name containing "OL"


query


PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX doap: <http://usefulinc.com/ns/doap#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX chem: <http://blueobelisk.sourceforge.net/chemistryblogs/>

SELECT ?compound ?compoundName ?compoundSmiles
{
?compound rdf:type chem:Compound .
?compound chem:name ?compoundName .
?compound chem:smiles ?compoundSmiles .
FILTER regex(?compoundName, "ol", "i")
}

result


------------------------------------------------------------------------------------------------------------------------------
| compound | compoundName | compoundSmiles |
==============================================================================================================================
| <http://en.wikipedia.org/wiki/Ethanol> | "Ethanol" | "OCC" |
| <http://commons.wikimedia.org/wiki/Image:D-Mannitol_structure.png> | "D-Manitol" | "O[C@H]([C@H](O)CO)[C@H](O)[C@H](O)CO" |
------------------------------------------------------------------------------------------------------------------------------

the same, but add the 'chem:description', if any


query


PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX doap: <http://usefulinc.com/ns/doap#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX chem: <http://blueobelisk.sourceforge.net/chemistryblogs/>

SELECT ?compound ?compoundName ?compoundSmiles ?description
{
?compound rdf:type chem:Compound .
?compound chem:name ?compoundName .
?compound chem:smiles ?compoundSmiles .
FILTER regex(?compoundName, "ol", "i")
OPTIONAL { ?compound chem:description ?description }

}

result


--------------------------------------------------------------------------------------------------------------------------------------------
| compound | compoundName | compoundSmiles | description |
============================================================================================================================================
| <http://en.wikipedia.org/wiki/Ethanol> | "Ethanol" | "OCC" | |
| <http://commons.wikimedia.org/wiki/Image:D-Mannitol_structure.png> | "D-Manitol" | "O[C@H]([C@H](O)CO)[C@H](O)[C@H](O)CO" | |
--------------------------------------------------------------------------------------------------------------------------------------------

retrieving Jean-Claude's data


The query


PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX chem: <http://blueobelisk.sourceforge.net/chemistryblogs/>

SELECT
?exp
?sample
?solvent ?solventName ?solventSmiles
?solute ?soluteName ?soluteSmiles
?conc

{
?solvent rdf:type chem:Compound .
?solvent chem:name ?solventName .
?solvent chem:smiles ?solventSmiles .

?solute rdf:type chem:Compound .
?solute chem:name ?soluteName .
?solute chem:smiles ?soluteSmiles .

?expData rdf:type chem:ExperimentalData .
?expData chem:solute ?solute .
?expData chem:solvent ?solvent .
?expData chem:concentration ?conc .
?expData chem:experiment-id ?exp .
?expData chem:sample ?sample .
}

result


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| exp | sample | solvent | solventName | solventSmiles | solute | soluteName | soluteSmiles | conc |
==================================================================================================================================================================================================================================================================================================
| <http://usefulchem.wikispaces.com/exp207> | <sample:12> | <http://en.wikipedia.org/wiki/Ethanol> | "Ethanol" | "OCC" | <http://en.wikipedia.org/wiki/Sodium_chloride> | "Sodium chloride" | "[Na+].[Cl-]" | "0.00"^^<chem:Molar> |
| <http://onschallenge.wikispaces.com/JennyHale-1> | <sample:3> | <http://en.wikipedia.org/wiki/Ethanol> | "Ethanol" | "OCC" | <http://en.wikipedia.org/wiki/Sodium_chloride> | "Sodium chloride" | "[Na+].[Cl-]" | "0.00"^^<chem:Molar> |
| <http://usefulchem.wikispaces.com/exp207> | <sample:11> | <http://en.wikipedia.org/wiki/Ethanol> | "Ethanol" | "OCC" | <http://commons.wikimedia.org/wiki/Image:D-Mannitol_structure.png> | "D-Manitol" | "O[C@H]([C@H](O)CO)[C@H](O)[C@H](O)CO" | "0.00"^^<chem:Molar> |
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


That's it

Pierre