How to make PyMOL draw bonds between atoms in console / script? - pymol

I want a PyMOL script to automatically draw bonds for a given structure, e.g. between all palladium atoms, or between all palladium and sulfur atoms.
I can do this manually by the bond command, but need to know the identifiers of the atoms:
bond id 3, id 4
bond id 2, id 6
...
How can I create all the desired bonds at once?
It would also be helpful, if a bond is created only, if the distance between the atoms is within a specific cutoff radius.

After crawling the PyMol mailinglist, I managed to connect all atoms. e.g.
bond (elem pd), (elem pd)
draws bonds between all the Pd atoms.
Now to the cuttoff radius:
bond (elem pd), (elem s) within 2.5 of (elem pd)
draws bonds between all Pd atoms and all S atoms within the range of 2.5 of any Pd atom. This is resulting in a weired structure with very long bonds.
I think it's necessary to iterate over one of both selections to yield bonds within the desired cutoff radius only.
Instead, I make use of the find_pairs function of pymol (this is API only and thus has to be used in a python script).
from pymol import cmd, stored
pd_s_bonds = cmd.find_pairs('n. pd', 'n. s', cutoff=2.5)
for pair in pd_s_bonds:
cmd.bond('index %s' % pair[0][6], 'index %s' % pair[1][7])

I have faced the same problem.
If you append indices to the names, you can use following syntax:
(elem P) within 2.5 of (name Ru1)
(elem P) within 2.5 of (name Ru2)

Related

How to extract a, b of johnsonsu.rvs() distribution from the first four moments mean, stdev, skewness and kurtosis?

So let's see that I have a code where:
mu=0 # first moment
rms=3 # second moment
skew=1 # third moment - skewness
kurt=3 # fourth moment - kurtosis
The problem is that I want to use these parameters as input and extract from them some a, b to feed my johnsonsu.rvs(a=?, b=?, loc=mu, scale=rms, size=[N,N]). I know that there is a way to derive the moments from a and b, but is there any way to do the opposite? (Probably it is just trivial math to do that, but I cannot understand).
I am translating a MATLAB code to python, where such distributions as johnsonsu, are derived from the first four moments, so there is no other way to do that.
I have ported the MATLAB code to estimate Johnson distributions parameters from moments
https://www.mathworks.com/matlabcentral/fileexchange/46123-johnson-curve-toolbox
to Python
https://github.com/maxdevblock/j_johnson_M
Usage
from j_johnson_M import f_johnson_M
coef, j_type, err = f_johnson_M(mu, sd, skew, kurt)
gamma, delta, xi, lam = coef

Breadth-first search with spiral ordered list of coordinates in Haskell

edit: This is getting down voted but it's not been made clear what data structure I should be using instead of a list of coordinates. Unfortunately my data comes as a flat list and it needs to be distributed with in an outwards clockwise spiral. Then run a BFS on that to work out islands. I used coordinates which is what the C++ code tutorial seem to do (I have zero C++ experience though) but seems that was a bad route to take in Haskell
I'm trying to accumulate a list of touching land cells grouped by islands.
Looking at the image bellow I'd expect 5 islands and each with the cells on that island. [[Cell]].
My input is currently a flat list of cells ordered in a clockwise spiral (red dotted line) and a number of the population of the cell. 0 making it sea and any >= 1 is the population.
data Cell = Cell
{ cellLoc :: (Int, Int)
, cellpop :: Int -- 0 sea, >= 1 population of land
}
startingCellList :: [Cell]
startingCellList =
[(Cell (1,0) 0)
,(Cell (1,-1) 0)
,(Cell (0,-1) 0)
,(Cell (-1,-1) 4)
]
The cellLoc gives me coordinates of cell in an X Y plane with (0,0) being at the centre of the grid. Am I right in thinking I can use the those coordinates to run my BSF?
Or do I need to rethink the use of coordinates to achieving my grid?
I've also found this great example but I'm not grasping it's use of vertexes and how or if I can relate it to using coordinates.
You can convert the list [(Int,Int)] into a Data.Set (Int,Int). Then you can quickly compute adjacency for your graph in the following way. Using this you can build your graph algorithm that finds components (in the complement of the graph, whatever).
import Data.Set
-- compute all possible neighbours as difference vectors
let adjDiff = [(dx,dy) | dx <- [-1..1], dy <- [-1..1], (dx,dy) /= (0,0)]
-- given a cell, compute all potential neighbouring cells
let adjFull (x,y) = [(x',y') | (dx,dy) <- adjDiff, let x'=x+dx, let y'=y+dy]
-- given a set of valid cells and a cell, compute all valid neighbours of this cell
let adj validCells cell = [n | n <- adjFull cell, member ValidCells n]

error message after spatstat::Gcross function: Error in marks.ppp(X, ...) : Sorry, not implemented when the marks are a data frame

I read a shapefile using maptools package and then converted to .ppp
hfmd <- readShapeSpatial("NEWMERGE.shp")
hfmd2 <- as(hfmd, 'ppp')
When I typed hfmd2, I received this
Marked planar point pattern: 1092 points`
Mark variables: X, Y, Status, ID`
window: rectangle = [492623.7, 609905.3] x [444011.4, 645190.4] units`
And when I typed Gcross(hfmd2) to run Cross G function, I received this error
Error in marks.ppp(X, ...) :`
Sorry, not implemented when the marks are a data frame`
My questions are:
Does Gcross() only work with Multitype Marked planar point pattern object?
How do I convert a .ppp object to a Multitype Marked planar point pattern object?
Your current ppp has four different mark values: X, Y, Status, ID. Which one do you want to use for Gcross? For now I will assume it is Status. Then you can replace the data.frame containing the four mark values for each point with a single mark vector like this:
marks(hfmd2) <- marks(hfmd2)$Status
Now you should be able to run Gcross:
Gc <- Gcross(hfmd2)
This will estimate Gcross between the first two types in Status.

Instrument string tension calculator in Haskell

I'm completely new to Haskell, so please bear that in mind
I'm working on a fairly simple (or so do I think) project - a string instrument tension calculator. Here's what I've got so far:
data Operator = Metric | Imperial
deriving Read
eval o l u p = case o of
Imperial -> (((2 * l * p)^2) * u) / 386.4
Metric -> (((2 * (l * 2.54) * p)^2) * u) / 386.4
prompt txt = do
putStrLn txt
readLn
main = do
o <- prompt "Metric or Imperial?"
l <- prompt "Scale length?"
u <- prompt "Gauge?" -- Unit Weight
p <- prompt "Pitch? (In hertz)"
putStrLn $ "The result is " ++ show (eval o l u p)
It lets you choose either Metric or Imperial for your scale length, and calculates the tension based on length, gauge and the desired pitch, giving you an output in pounds.
What I'm having a problem with is: I want the calculator to fetch me unit weight based on the gauge number I input.
I want to change the "u" in
u <- prompt "Gauge?" -- Unit Weight
to a "g", and if the "g" matches a number from 0.07 to 0.80, it returns me the unit weight of "u" corresponding to the gauge from a table, for example, the unit weight for a gauge of 0.80 would be 0.00115011, and I want it to be reflected in the equation.
How would I go about that? What do I need to do to create a table/list of the "g" values giving "u"'s?
The table and the equation I'm using, by the way: http://www.daddario.com/upload/tension_chart_13934.pdf
I'll give you an hint for a basic solution.
Define your map as a list of pairs (gauge, unitWeight). Make it ordered according to gauge.
gw :: [(Double, Double)]
gw = [(1, 2), (2, 4), ... ]
Then, assume you have a g to lookup. You want to discard from gw all the initial pairs with gauge <g. For that, you can use
dropWhile (some predicate here) gw
then, you can take the first pair element in the remaining list, and extract the unit weight.
This is not terribly efficient since you scan almost the whole list every time, depending on your gauge. One could improve this with Data.Map.Map. Yet, for a beginner exercise, using a list should do. You probably won't have a huge amount of list items anyway, so the program should still be pretty fast.

Generate 2D list with given dimensions in Haskell

I am trying to generate a list of lists with a specified dimension.
the data type of this list looks something like this:
data A = X | Y | Z
so the list is of type [[A]]. (A is an instance of the Show type class so don't worry about that).
The user gives in a certain dimension (lets say width = 3 and height = 4), so the content could look like this:
[[X,Y,Z],
[Y,Y,X],
[Y,X,Z],
[X,Z,Z]]
How can I generate a width X height 'matrix', the values aren't all that important at the moment.
thanks in advance.
EDIT: (for clarity reasons)
I just want to know how to generate a 'matrix' of type [[A]] with the width and height as user input.
So width = number of elements in the inner list, height = number of lists in the outer list.
To generate a 3x4 nested list filled by a certain element, you can use:
data A = X | Y | Z deriving (Show)
generate width height = replicate height . replicate width
main = print $ generate 3 4 X
to get [[X,X,X],[X,X,X],[X,X,X],[X,X,X]].
Note that nested lists are not a great substitute for a 2D array in C/Java if the goal is to do frequent point updates. In those cases, use Data.Map or Data.Array.

Resources