def P(self): """Returns the computed SOAP matrices for each GB in the collection. """ result = self.store.P if len(result) == 0: msg.info("The SOAP matrices haven't been computed yet. Use " ":meth:`soap`.") return result
def Scatter(self): """Returns the computed Scatter vectors for each GB in the collection """ result = self.store.Scatter if len(result) == 0: msg.info("The Scatter vectors haven't been computed yet. Use " ":meth:`scatter`.") return result
def load(self, parser=None, custids=None, name=None, fname=None, **selectargs): """Loads the GBs from their files to create :class:`GrainBoundary` objects. .. note:: The :class:`GrainBoundary` objects are stored in this objects dictionary (it inherits from :class:`~collections.OrderedDict`). Thus :attr:`keys` are the `gbid` and :attr:`values` are the :class:`GrainBoundary` instances, in the sorted order that they were discovered. .. note:: If 'coord' is not given as a selectarg, load will determine and use the coordinate along the longest dimension. Args: parser: object used to parse the raw GB file. Defaults to :class:`gblearn.lammps.Timestep`. Class should have a method `gb` that constructs a :class:`GrainBoundary` instance. custids (dict or str): if `dict`, keys are `str` GB ids and values are the custom selection method to use. If `str`, then a TSV file where the first column is GB id and the second is the custom selection method to use. name (str): unique id of external grain boundary fname (str): filenme to the grain boundary file ..warning:: the filenmae automattically adds the root path selectargs (dict): keyword arguments passed to `parser` when isolating grain boundary atoms. """ if parser is None: from gblearn.lammps import Timestep parser = Timestep if custids is not None and isinstance(custids, six.string_types): rawids = np.loadtxt(custids, dtype=str).tolist() custids = {g: m for g, m in enumerate(rawids)} if fname is not None: if name is None: # pragma: no cover msg.info( "Name not specified, using {} as unique identifier".format( fname)) name = fname gbpath = path.join(self.root, fname) self.others[name] = self._parse_gb(gbpath, parser, **selectargs) return for gbid, gbpath in tqdm(self.gbfiles.items()): if custids is not None and gbid in custids: selectargs["method"] = custids[gbid] self[gbid] = self._parse_gb(gbpath, parser, **selectargs)
def _find_gbs(self): """Finds all the GBs in the root directory using the regex. """ from os import walk allfiles = [] for (dirpath, dirnames, filenames) in walk(self.root): allfiles.extend(filenames) break for fname in sorted(allfiles, key=self._sortkey, reverse=self._reverse): if self._rxgbid is not None: gbmatch = self._rxgbid.match(fname) if gbmatch: try: gbid = gbmatch.group("gbid") self.gbfiles[gbid] = path.join(self.root, fname) except IndexError: # pragma: no cover pass else: self.gbfiles[fname] = path.join(self.root, fname) msg.info("Found {} grain boundaries.".format(len(self.gbfiles)))