Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
WebChemistry Wiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
PatternQuery:Principles
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Example, Part One== Let’s assume we have loaded a protein stored in a PDB or mmCIF file with correctly annotated HET groups and '''we want to find all HET residues in it'''. The characteristics of an imperative approach is explicitly stating steps that need to be performed in order achieve a particular goal. In contrast a declarative approach states the goal we would like to achieve, leaving the individual steps as an "implementation detail". Using the imperative approach, we would do something like this: <syntaxhighlight lang="python"> result = List() for residue in molecule.Residues: if residue.IsHet(): result.Add(residue) </syntaxhighlight> In the declarative approach, our code would look like this: <syntaxhighlight lang="python"> HetResidues() </syntaxhighlight> Now, let’s extend our example to "all HET residues and atoms within 4A around them". In the imperative approach we would need to do something along the following lines: <syntaxhighlight lang="python"> temp = List() for residue in molecule.Residues(): if residue.IsHet(): temp.Add(residue) neighborhoodLookup = NeighborhoodLookup(molecule.Atoms()) result = List() for residue in temp: surroundings = neiborhoodLookup.Find(residue.Atoms, 4.0) result.Add(union(residue, surroundings)) return result </syntaxhighlight> Declaratively, our code would be just: <syntaxhighlight lang="python"> HetResidues().AmbientAtoms(4.0) </syntaxhighlight> Internally, the function <code>[[PatternQuery:Language_Reference#AmbientAtoms | AmbientAtoms()]]</code> might run code similar to the imperative version. However, what is important is that this complexity is hidden from the user when the declarative approach is used. Now, let’s extend our example even further: "all HET residues and atoms within 4A around them, where the entire structure contains at least one calcium atom". We will not bother the reader with writing down the imperative version - implementing the condition "at least one calcium atom" is rather boring. However, using the declarative approach, the description of the pattern becomes simply: <syntaxhighlight lang="python"> HetResidues() .AmbientAtoms(4.0) .Filter(lambda m: m.Count(Atoms('Ca')) >= 1) </syntaxhighlight>
Summary:
Please note that all contributions to WebChemistry Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
WebChemistry Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Search
Search
Editing
PatternQuery:Principles
(section)
Add topic