github.com/rmera/gochem@v0.7.1/interfaces.go (about) 1 /* 2 * interfaces.go, part of gochem. 3 * 4 * 5 * Copyright 2012 Raul Mera <rmera{at}chemDOThelsinkiDOTfi> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation; either version 2.1 of the 10 * License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General 18 * Public License along with this program. If not, see 19 * <http://www.gnu.org/licenses/>. 20 * 21 * 22 * Gochem is developed at the laboratory for instruction in Swedish, Department of Chemistry, 23 * University of Helsinki, Finland. 24 * 25 * 26 */ 27 28 package chem 29 30 import v3 "github.com/rmera/gochem/v3" 31 32 /*The plan is equate PDBs XTCs and in the future DCDs. One needs to separate the molecule methods between actual molecule methods, that requires atoms and coordinates, []atom methods, and DenseMatrix 33 * methods. Then one must implements objects for Xtc trajs that are more or less equivalent to molecules and set up an interface so many analyses can be carried out exactly the same from 34 * multiPDB or XTC or (eventually) DCD*/ 35 36 //Traj is an interface for any trajectory object, including a Molecule Object 37 type Traj interface { 38 39 //Is the trajectory ready to be read? 40 Readable() bool 41 42 //reads the next frame and returns it as DenseMatrix if keep==true, or discards it if false 43 //it can also fill the (optional) box with the box vectors, it present in the frame. 44 Next(output *v3.Matrix, box ...[]float64) error 45 46 //Returns the number of atoms per frame 47 Len() int 48 } 49 50 //ConcTraj is an interface for a trajectory that can be read concurrently. 51 type ConcTraj interface { 52 53 //Is the trajectory ready to be read? 54 Readable() bool 55 56 /*NextConc takes a slice of bools and reads as many frames as elements the list has 57 form the trajectory. The frames are discarted if the corresponding elemetn of the slice 58 is false. The function returns a slice of channels through each of each of which 59 a *matrix.DenseMatrix will be transmited*/ 60 NextConc(frames []*v3.Matrix) ([]chan *v3.Matrix, error) 61 62 //Returns the number of atoms per frame 63 Len() int 64 } 65 66 //Atomer is the basic interface for a topology. 67 type Atomer interface { 68 69 //Atom returns the Atom corresponding to the index i 70 //of the Atom slice in the Topology. Should panic if 71 //out of range. 72 Atom(i int) *Atom 73 74 Len() int 75 } 76 77 //AtomChargerMultier is atomer but also gives a 78 //charge and multiplicity 79 type AtomMultiCharger interface { 80 Atomer 81 82 //Charge gets the total charge of the topology 83 Charge() int 84 85 //Multi returns the multiplicity of the topology 86 Multi() int 87 } 88 89 //Masser can return a slice with the masses of each atom in the reference. 90 type Masser interface { 91 92 //Returns a column vector with the massess of all atoms 93 Masses() ([]float64, error) 94 } 95 96 //Errors 97 98 //Error is the interface for errors that all packages in this library implement. The Decorate method allows to add and retrieve info from the 99 //error, without changing it's type or wrapping it around something else. 100 type Error interface { 101 Error() string 102 Decorate(string) []string //This is the new thing for errors. It allows you to add information when you pass it up. Each call also returns the "decoration" slice of strins resulting from the current call. If passed an empty string, it should just return the current value, not add the empty string to the slice. 103 //The decorate slice should contain a list of functions in the calling stack, plus, for each function any relevant information, or nothing. If information is to be added to an element of the slice, it should be in this format: "FunctionName: Extra info" 104 } 105 106 //TrajError is the nterface for errors in trajectories 107 type TrajError interface { 108 Error 109 Critical() bool 110 FileName() string 111 Format() string 112 } 113 114 //LastFrameError has a useless function to distinguish the harmless errors (i.e. last frame) so they can be 115 //filtered in a typeswith that looks for this interface. 116 type LastFrameError interface { 117 TrajError 118 NormalLastFrameTermination() //does nothing, just to separate this interface from other TrajError's 119 120 }