def rms(config, inp: Tuple[str, str], out: click.File): """Calculate the root mean squared deviation between two structures using quaternions. Based on a Fortran implementation by Chaok Seok, Evangelos Coutsias, and Ken Dill.""" from kallisto.rmsd import rmsd mol1 = ksr.constructMolecule(geometry=inp[0], out=out) nat1 = mol1.get_number_of_atoms() mol2 = ksr.constructMolecule(geometry=inp[1], out=out) nat2 = mol2.get_number_of_atoms() # for RMSD comparison both coordinates need the same atom count if nat1 != nat2: errorbye( "Error: number of atoms do not match in {} and in {}".format( inp[0], inp[1]), ) coord1 = mol1.get_positions() coord2 = mol2.get_positions() # get RMSD error and rotation matrix u error, u = rmsd(nat1, coord1, coord2) silentPrinter(config.silent, "RMSD {} Angstrom".format(error), out) silentPrinter(config.silent, "Rotation Matrix", out) click.echo(u, file=out) # type: ignore return error, u
def vdw(config, inp: str, out: click.File, chrg: int, vdwtype: str, angstrom: bool): """Charge-dependent atomic van der Waals radii in Bohr.""" # Available VDWs availableVDW = ("rahm", "truhlar") if vdwtype not in availableVDW: errorbye( 'VDW definition "{}" is not implemented. Please use "rahm" or "truhlar"'.format( vdwtype ) ) molecule = ksr.constructMolecule(geometry=inp, out=out) nat = molecule.get_number_of_atoms() if angstrom: from kallisto.units import Bohr scale = Bohr else: scale = 1.0 vdw = molecule.get_vdw(chrg, vdwtype, scale) for i in range(nat): silentPrinter(config.silent, vdw[i], out) return vdw
def constructMolecule(geometry: str, out: click.File) -> Molecule: """Helper function to construct a Molecule.""" try: with open(geometry, "r+") as fileObject: # read atoms from input file atoms = read(fileObject) # create molecule from atoms molecule = Molecule(symbols=atoms) except FileNotFoundError: errorbye("Input file not found.") return molecule
def prox(config, inp: str, size: Tuple[int, int], out: click.File): """Atomic proximity shells.""" # Stop if outer border is smaller than inner one if size[0] > size[1]: errorbye("Outer border is smaller than inner one. Switch them and try again!") molecule = ksr.constructMolecule(geometry=inp, out=out) nat = molecule.get_number_of_atoms() prox = molecule.get_prox(size) for i in range(nat): silentPrinter(config.silent, prox[i], out) return prox
def cns(config, inp: str, out: click.File, cntype: str): """Atomic coordination numbers.""" # Available CNs availableCN = ("erf", "cov", "exp") if cntype not in availableCN: errorbye( 'CN definition "{}" is not implemented. Please use "erf", "cov", or "exp"' .format(cntype)) molecule = ksr.constructMolecule(geometry=inp, out=out) cns = molecule.get_cns(cntype) nat = molecule.get_number_of_atoms() for i in range(nat): silentPrinter(config.silent, cns[i], out) return cns
def read(fileObject): """Method to first check the file type and then read the structure accordingly The returned atom coordinates will be in Bohr """ fname = fileObject.name.lower() filetp = "unknown" lines = fileObject.readlines() if fname.endswith((".xyz")): filetp = "xyz" else: for line in lines: if line.strip().startswith("$coord"): filetp = "turbomole" break fileObject.close() atoms = [] newfile = open(fname, "r+") if filetp == "turbomole": atoms = tm.read(newfile) elif filetp == "xyz": atoms = xyz.read(newfile) else: errorbye("Input format erroneous or not implemented.") newfile.close() return atoms