Exemple #1
0
func BackBone(stdin *bufio.Reader, options *chemjson.Options, i int) (coords, optcoords *v3.Matrix, optatoms *chem.Topology, list, frozen []int) {
	mol, coordarray, err := chemjson.DecodeMolecule(stdin, options.AtomsPerSel[i], 1)
	if err != nil {
		fmt.Fprint(os.Stderr, err.Marshal())
		log.Fatal(err)
	}
	coords = coordarray[0]

	//chem.PDBWrite("OPTpp.pdb", mol,coords,nil) /////////////////////////////////////
	resid, chain := GetResidueIds(mol)
	fmt.Fprintln(os.Stderr, "resid, chains, atomspersel, i", resid, chain, options.AtomsPerSel[i], i)
	var err2 error
	list, err2 = chem.CutBackRef(mol, []string{chain[0]}, [][]int{resid[1 : len(resid)-1]}) //in each backbone selection the chain should be the same for all residues
	if err != nil {
		panic(err2.Error()) //at least for now
	}
	optcoords = v3.Zeros(len(list))
	optcoords.SomeVecs(coords, list)
	optatoms = chem.NewTopology(nil, 0, 0) //the last 2 options are charge and multiplicity
	optatoms.SomeAtoms(mol, list)
	chem.ScaleBonds(optcoords, optatoms, "NTZ", "HNZ", chem.CHDist)
	chem.ScaleBonds(optcoords, optatoms, "CTZ", "HCZ", chem.CHDist)
	frozen = make([]int, 0, 2*len(list))
	for i := 0; i < optatoms.Len(); i++ {
		curr := optatoms.Atom(i)
		//In the future there could be an option to see whether C and N are fixed
		if curr.Name == "NTZ" || curr.Name == "CTZ" || curr.Name == "C" || curr.Name == "N" {
			frozen = append(frozen, i)
		}
	}
	return coords, optcoords, optatoms, list, frozen
}
Exemple #2
0
func SideChains(stdin *bufio.Reader, options *chemjson.Options) (coords, optcoords *v3.Matrix, optatoms *chem.Topology, list, frozen []int) {
	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]
	resid, chains := GetResidueIds(mol)
	//	fmt.Fprintln(os.Stderr,"SIDE! resid, chains", resid, chains)
	toscale := []string{"CA", "HA2", "HA3"}
	if options.BoolOptions[0][1] {
		list = chem.CutAlphaRef(mol, chains, resid)
	} else {
		list = chem.CutBetaRef(mol, chains, resid)
		toscale = []string{"CB", "HB4", "HB4"} //Yes, I am doing this twice for no reason other to have 3 elements in this slice.
	}
	optcoords = v3.Zeros(len(list))
	optcoords.SomeVecs(coords, list)
	optatoms = chem.NewTopology(nil, 0, 0) //the last 2 options are charge and multiplicity
	optatoms.SomeAtoms(mol, list)
	chem.ScaleBonds(optcoords, optatoms, toscale[0], toscale[1], chem.CHDist)
	chem.ScaleBonds(optcoords, optatoms, toscale[0], toscale[2], chem.CHDist)
	frozen = make([]int, 0, 2*len(list))
	for i := 0; i < optatoms.Len(); i++ {
		curr := optatoms.Atom(i)
		if curr.Name == "HA" || curr.Name == "CA" || curr.Name == "CB" {
			frozen = append(frozen, i)
		}
	}
	return coords, optcoords, optatoms, list, frozen
}
Exemple #3
0
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)
	}

}
Exemple #4
0
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())
	}
}