func main() { //This is the part that collects all the data from PyMOL, with all the proper error checking. stdin := bufio.NewReader(os.Stdin) options, err := chemjson.DecodeOptions(stdin) if err != nil { fmt.Fprint(os.Stderr, err.Marshal()) log.Fatal(err) } mol, coordarray, err := chemjson.DecodeMolecule(stdin, options.AtomsPerSel[0], 1) if err != nil { fmt.Fprint(os.Stderr, err.Marshal()) log.Fatal(err) } coords := coordarray[0] var rep *os.File //The program itself for { reportname := strings.Join([]string{"reduce_report", options.SelNames[0], "log"}, ".") rep, err2 := os.Create(reportname) if err2 != nil { break } defer rep.Close() break } var build int if len(options.IntOptions) == 0 || len(options.IntOptions[0]) == 0 { build = 2 } else { build = options.IntOptions[0][0] } newmol, err2 := chem.Reduce(mol, coords, build, rep, "reduce") if err2 != nil { // if err,ok :=err2.(chem.Error); ok{ // fmt.Println(err.Decorate("")) // } // fmt.Println(err2)////////// fmt.Fprint(os.Stderr, chemjson.NewError("process", "chem.Reduce", err2)) //Not always fatal. if newmol == nil { // !strings.Contains(err2.Error(),"invalid argument"){ log.Fatal(err2) } } //Start transfering data back info := new(chemjson.Info) info.Molecules = 1 info.FramesPerMolecule = []int{1} info.AtomsPerMolecule = []int{newmol.Len()} if err2 := info.Send(os.Stdout); err2 != nil { fmt.Fprint(os.Stderr, err2) log.Fatal(err2) } // fmt.Fprint(os.Stdout,mar) // fmt.Fprint(os.Stdout,"\n") if err2 := chemjson.SendMolecule(newmol, newmol.Coords, nil, nil, os.Stdout); err2 != nil { fmt.Fprint(os.Stderr, err2) log.Fatal(err2) } }
func main() { //This is the part that collects all the data from PyMOL, with all the proper error checking. stdin := bufio.NewReader(os.Stdin) options, errj := chemjson.DecodeOptions(stdin) if errj != nil { fmt.Fprint(os.Stderr, errj.Marshal()) log.Fatal(errj) } mols := make([]*chem.Topology, 0, len(options.SelNames)) coordset := make([]*v3.Matrix, 0, len(options.SelNames)) for k, _ := range options.SelNames { mol, coords, errj := chemjson.DecodeMolecule(stdin, options.AtomsPerSel[k], 1) if errj != nil { fmt.Fprint(os.Stderr, errj.Marshal()) log.Fatal(errj) } mols = append(mols, mol) coordset = append(coordset, coords[0]) } //The program itself ramadata := make([][][]float64, 0, 0) var HLS [][]int var HL []int for k, mol := range mols { fmt.Println("len in go", mol.Len(), coordset[k].NVecs()) ////// HL = []int{} oldres1 := mol.Atom(0).MolID + 1 //the residues should be contiguous!!! chem.FixNumbering(mol) ramalist, errj := chemplot.RamaList(mol, "ABC DEFGHI", []int{0, -1}) //// if errj != nil { log.Fatal(errj) } ramalist2, index := chemplot.RamaResidueFilter(ramalist, options.StringOptions[0], false) rama, errj := chemplot.RamaCalc(coordset[k], ramalist2) if errj != nil { log.Fatal(errj) } ramadata = append(ramadata, rama) var i int if options.IntOptions != nil && options.IntOptions[0] != nil { for i = 0; i < len(ramalist); i++ { fmt.Println(i, i+oldres1, index[i], options.IntOptions[0]) if index[i] != -1 && scu.IsInInt(i+oldres1, options.IntOptions[0]) { HL = append(HL, index[i]) fmt.Println("NAME:", ramalist[index[i]].Molname) } } HLS = append(HLS, HL) } } name := append(options.SelNames, "Rama") var err error if len(ramadata) == 1 { err = chemplot.RamaPlot(ramadata[0], HL, "Ramachandran plot", strings.Join(name, "_")) } else { err = chemplot.RamaPlotParts(ramadata, HLS, "Ramachandran plot", strings.Join(name, "_")) } if err != nil { fmt.Fprint(os.Stderr, chemjson.NewError("process", "main", err).Marshal()) } }