def getSubstructureFromPath(refmol: Molecule, path: np.ndarray) -> Molecule: """Create a molecules object from a substructure of given molecule.""" # initialize refat = refmol.get_atomic_numbers() refxyz = refmol.get_positions() # atoms from complex excluding old substrate atoms = [] for elem in path: atom = Atom(symbol=refat[elem], position=refxyz[elem, :]) atoms.append(atom) # create molecule from atoms return Molecule(symbols=atoms)
def test_user_can_get_atomic_numbers(): reference = Molecule(atoms) numbers = reference.get_atomic_numbers() assert numbers[0] == 1
def exchangeSubstructure( n: int, center: int, subnr: int, bonds, ref: Molecule, newsub: Molecule, newSubBonds, name: str, rotate: int, exclude: bool, ) -> Molecule: """Exchange substructure (subnr) from ref with substrate.""" # setup initial complex refxyz = ref.get_positions() refat = ref.get_atomic_numbers() refnat = ref.get_number_of_atoms() # match new and old substrate newat = newsub.get_atomic_numbers() newnat = newsub.get_number_of_atoms() # extract coordinates of central atom centralAtom = refxyz[center, :] mol = Molecule() for i in range(len(bonds[center])): if i == subnr: path = np.zeros(shape=(n, ), dtype=np.int32) # set all elements to -1 path.fill(-1) partner = bonds[center][i] count = Counter() # type: ignore count["step"] = -1 getSubstructures(n, bonds, center, partner, path, count=count) # get rid of -1 elements path = [x for x in path if x != -1] path = np.array(path) # create molecule from given path oldsub = getSubstructureFromPath(ref, path) # get all bonding partner oldSubBonds = oldsub.get_bonds(partner="X") outxyz = matchSubstrates( bonds, newsub, newSubBonds, oldsub, oldSubBonds, centralAtom, ) # atoms from complex excluding old substrate atoms = [] for j in range(refnat): if j in path: continue atom = Atom(symbol=refat[j], position=refxyz[j, :]) atoms.append(atom) # atoms from new substrate # Should we rotate the substrate around covalent bond? if rotate: theta = rotate origin = refxyz[center, :] partner = outxyz[0, :] outxyz2 = np.zeros(shape=outxyz.shape, dtype=np.float64) # reference shift refShift = getRodriguezRotation(partner, origin, partner, theta) shift = outxyz[0, :] - refShift for j in range(newnat): outxyz2[j, :] = getRodriguezRotation( outxyz[j, :], origin, partner, theta, ) outxyz2[j, :] += shift atom = Atom(symbol=newat[j], position=outxyz2[j, :]) atoms.append(atom) else: for j in range(newnat): atom = Atom(symbol=newat[j], position=outxyz[j, :]) atoms.append(atom) # create molecule from atoms mol = Molecule(symbols=atoms) # write new structure in xyz format mol.writeMolecule(name + ".xyz") # write constrain file refnat = ref.get_number_of_atoms() oldnat = oldsub.get_number_of_atoms() nat = refnat - oldnat writeTransitionMetalConstrains(nat, newnat, newSubBonds, exclude) return mol return mol