def toASE(molecule): """Convert a PLAMS |Molecule| to an ASE molecule (``ase.Atoms`` instance). Translate coordinates, atomic numbers, and lattice vectors (if present). The order of atoms is preserved.""" aseMol = aseAtoms() #iterate over PLAMS atoms for atom in molecule: #check if coords only consists of floats or ints if not all(isinstance(x, (int,float)) for x in atom.coords): raise ValueError("Non-Number in Atomic Coordinates, not compatible with ASE") #append atom to aseMol aseMol.append(aseAtom(atom.atnum, atom.coords)) #get lattice info if any lattice = npz((3,3)) pbc = [False,False,False] for i,vec in enumerate(molecule.lattice): #check if lattice only consists of floats or ints if not all(isinstance(x, (int,float)) for x in vec): raise ValueError("Non-Number in Lattice Vectors, not compatible with ASE") pbc[i] = True lattice[i] = npa(vec) #save lattice info to aseMol if any(pbc): aseMol.set_pbc(pbc) aseMol.set_cell(lattice) return aseMol
def get_vocabulary(self, docs, nWords): from numpy import zeros as npz print("===========================") print("CORPUS VOCABULARY DISTRIBUTION") print("===========================") message = "Words\t\tCount" words = self.vectorizer.get_feature_names() total_counts = npz(len(words)) for t in self.vector: total_counts += t.toarray()[0] count_dict = zip(words, total_counts) count_dict = sorted(count_dict, key=lambda x: x[1], reverse=True)[0:nWords] print_list(count_dict, message) print("\n") return self.vectorizer.vocabulary_
def toASE(molecule): """ Converts a PLAMS molecule to an ASE molecule. The following attributes are converted, conserving the order of atoms: -Coordinates -Atomic Number (Symbol is derived automaticaly) -Periodicity and Cell Vectors """ aseMol = aseAtoms() #iterate over PLAMS atoms for atom in molecule: #check if coords only consists of floats or ints if not all(isinstance(x, (int, float)) for x in atom.coords): raise ValueError( "Non-Number in Atomic Coordinates, not compatible with ASE") #append atom to aseMol aseMol.append(aseAtom(atom.atnum, atom.coords)) #get lattice info if any lattice = npz((3, 3)) pbc = [False, False, False] for i, vec in enumerate(molecule.lattice): #check if lattice only consists of floats or ints if not all(isinstance(x, (int, float)) for x in vec): raise ValueError( "Non-Number in Lattice Vectors, not compatible with ASE") pbc[i] = True lattice[i] = npa(vec) #save lattice info to aseMol if any(pbc): aseMol.set_pbc(pbc) aseMol.set_cell(lattice) return aseMol