Example #1
0
// Best returns the number of the fragment that best corresponds
// to the region of atoms provided.
// The length of `atoms` must be equivalent to the fragment size.
func (lib *structureAtoms) BestStructureFragment(atoms []structure.Coords) int {
	var testRmsd float64
	mem := lib.rmsdMemory()
	bestRmsd, bestFragNum := 0.0, -1
	for _, frag := range lib.Fragments {
		testRmsd = structure.RMSDMem(mem, atoms, frag.FragAtoms)
		if bestFragNum == -1 || testRmsd < bestRmsd {
			bestRmsd, bestFragNum = testRmsd, frag.FragNumber
		}
	}
	return bestFragNum
}
Example #2
0
// BestMem returns the number of the fragment that best corresponds
// to the region of atoms provided without allocating.
// The length of `atoms` must be equivalent to the fragment size.
//
// `mem` must be a region of reusable memory that should only be accessed
// from one goroutine at a time. Valid values can be constructed with
// rmsdMemory.
func (lib *StructureLibrary) bestMem(
	atoms []structure.Coords,
	mem structure.Memory,
) int {
	var testRmsd float64
	bestRmsd, bestFragNum := 0.0, -1
	for _, frag := range lib.Fragments {
		testRmsd = structure.RMSDMem(mem, atoms, frag.Atoms)
		if bestFragNum == -1 || testRmsd < bestRmsd {
			bestRmsd, bestFragNum = testRmsd, frag.Number
		}
	}
	return bestFragNum
}