how to import demo ("md") on python by using rpy2

Issue #290 invalid
Ayesha kanwal
created an issue

i am new on rpy2 and i don't know how to import demo on python by using rpy2 please help me. i am using ubunto 14.0 version and python 2.7 version. it give following error :

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2
Type "copyright", "credits" or "license()" for more information.
>>> from rpy2.robjects.packages import importr
>>> library = importr ("bio3d")
>>> demo("md")

**Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    demo("md")
NameError: name 'demo' is not defined

Comments (5)

  1. Ayesha kanwal reporter

    how can i write R function in pyhton to run this demo ? please help me its my project and i am very new for this my project is stucked for about 2 weeks i am very worried about my project even if you can provide me any helpful material regarding to my question then i will be very thankful to you. please give me answer as soon as possible i am waiting for your reply.

  2. Laurent Gautier

    If this is an assignment your teacher or schoolmates should be be consulted. The important is that you learn to do it in he context of your curriculum ( which I do not know). A copy/paste will only bump you down to the next stopper.

    Here the issue is that "demo" is not a Python variable (as the error message from Python suggests it). The function demo is present in R, so should be fetched from there by one of the access points rpy2 is providing.

  3. Ayesha kanwal reporter

    how can i correctly fetch it from rpy2 please give me an example so i can understand this in a better way . my supervisor didn't help me in this project as i want to use PCA codes that are given in R language on bio3D but i want to transfer that code in python by using rpy2 . the problem is that no one help me in this context and i am totally new in this field and i have very less time to cover it , the only source i have to get correct dimension is only you. please help me that how i use these commands and transfer them in python through rpy2

    library(bio3d)
    demo("md")
    mydcdfile <- "/path/to/my/data/myfile.dcd"
    dcd <- read.dcd(dcdfile)
    pdb <- read.pdb(pdbfile)
    ca.inds <- atom.select(pdb, elety="CA")
    xyz <- fit.xyz(fixed=pdb$xyz, mobile=dcd,
                   fixed.inds=ca.inds$xyz,
                   mobile.inds=ca.inds$xyz)
    dim(xyz) == dim(dcd)
    pc <- pca.xyz(xyz[,ca.inds$xyz])
    plot(pc, col=bwr.colors(nrow(xyz)) )
    hc <- hclust(dist(pc$z[,1:2]))
    grps <- cutree(hc, k=2)
    plot(pc, col=grps)
    plot.bio3d(pc$au[,1], ylab="PC1 (A)", xlab="Residue Position", typ="l")
    points(pc$au[,2], typ="l", col="blue")
    
    p1 <- mktrj.pca(pc, pc=1, b=pc$au[,1], file="pc1.pdb")
    p2 <- mktrj.pca(pc, pc=2,b=pc$au[,2], file="pc2.pdb")
    write.ncdf(p1, "trj_pc1.nc")
    
  4. Log in to comment