Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with isvalid.formula #96

Open
arthuc01 opened this issue May 1, 2019 · 0 comments
Open

Problem with isvalid.formula #96

arthuc01 opened this issue May 1, 2019 · 0 comments

Comments

@arthuc01
Copy link

arthuc01 commented May 1, 2019

This works....

> formula <- get.formula('C6H19KN2O10', charge = 1)
> isvalid.formula(formula,rule=c("nitrogen","RDBE"))
[1] FALSE

But when I try....

> formula <- get.formula('C5H13KN9O5', charge = 1)
> isvalid.formula(formula,rule=c("nitrogen","RDBE"))

Error in .jcall(rdbeRule, "D", "validate", molecularFormula) : 
  java.lang.NullPointerException

I'm trying to validate formulae generated with generate.formula

library(rcdk)

molFormula <- function(mz){
  ppm = (2/1000000)*mz
  temp <- generate.formula(mz, window=(2/1000000)*mz,
                            elements=list(c("C",0,120),
                                          c("H",0,180),
                                          c("N",0,20),
                                          c("O",0,20),
                                          c("S",0,20),
                                          c("Na",0,1),
                                          c("K",0,1)
                                          ),
                            validation=FALSE, charge =1)
  df <- data.frame(matrix(ncol = 4, nrow = 0))
  x <- c("formula", "mass", "charge", "ppmError")
  colnames(df) <- x
  
  for (i in temp) {
    print(i@string)
    formula <- get.formula(i@string, charge = 1)
    print(isvalid.formula(formula,rule=c("nitrogen","RDBE")))
  
  }
  return (df)
}


mz <-318.06768


formulae <- molFormula(mz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant