PYTHON/utils.py
def calc_intermolecular_atom_distances(crystal):
    '''
    Calculates all interatomic atom atom distances in a crystal structure
    calculates distances on batch between central molecules and a neighbour molecule, rather than a simple
    nested for loop
    calculates distances in batches between atom i in central molecule and atom (i - x) in neighbour
    returns a dataframe with all atom atom distances < 10A in the crystal structure
    '''
    # Calculate Atom Distances from central molecule
    central_molecule, central_idx = crystal.get_central_molecule(return_idx=True)
    central_atom_coords = np.array([atom.coordinates for atom in central_molecule.atoms]) # shape = (n_atoms,3)
    all_atom_coords = []
    for mol in crystal.molecules:
        all_atom_coords.append(np.array([atom.coordinates for atom in mol.atoms]))
    all_atom_coords = np.array(all_atom_coords) # shape = (n_mols,n_atoms,3) 
    dists = []
    mol1s = []
    mol2s = []
    for i, mol_coords in enumerate(all_atom_coords):
        temp_dist = []
        for x in range(len(mol_coords)):
            mol1s += [central_idx]*len(mol_coords)
            mol2s += [i]*len(mol_coords)
            disp = mol_coords - central_atom_coords # shape = (n_atoms,3)
            dist2 = disp[:,0] * disp[:,0] + disp[:,1] * disp[:,1] + disp[:,2] * disp[:,2]
            dist = np.sqrt(dist2) # shape = (n_atoms)
            temp_dist.append(dist)
            mol_coords = np.roll(mol_coords,-1,axis=0)
        dists.append(temp_dist)
    dists = np.array(dists) # shape = (n_molecules,x_atoms,y_atoms) | where y in y_atoms = dist(atom_x_central - atom_y_mol_n)
    # Put distances in order of atom indices
    in_atom_order = np.array([dist.flatten('F') for dist in dists]).reshape(-1)
    d1 = dists.shape[0]
    d2 = dists.shape[1]
    arange = np.arange(d2)
    atom1s = np.concatenate([[x]*d2 for x in range(d2)]*d1)
    atom2s = np.concatenate([np.roll(arange,-x) for x in range(d2)]*d1)
    #atom2s = np.concatenate([[x for x in range(d2)]*d2]*d1)
    # Turn Atom Distances to DataFrame
    data_dict= {'mol1s':mol1s,'mol2s':mol2s,'atom1s':atom1s,'atom2s':atom2s,'dists':in_atom_order}
    atom_dist_df = pd.DataFrame(data_dict)
    atom_dist_df = atom_dist_df[atom_dist_df.mol1s != atom_dist_df.mol2s]
    atom_dist_df = atom_dist_df.loc[atom_dist_df.dists <= 10]
    
    return atom_dist_df

    Calculates all interatomic atom atom distances in a crystal structure
    calculates distances on batch between central molecules and a neighbour molecule, rather than a simple
    nested for loop
    calculates distances in batches between atom i in central molecule and atom (i - x) in neighbour
    returns a dataframe with all atom atom distances < 10A in the crystal structure
    
Calculates all interatomic atom atom distances in a crystal structure
calculates distances on batch between central molecules and a neighbour molecule, rather than a simple
nested for loop
calculates distances in batches between atom i in central molecule and atom (i - x) in neighbour
returns a dataframe with all atom atom distances < 10A in the crystal structure
Calculates all interatomic atom atom distances in a crystal structure calculates distances on batch between central molecules and a neighbour molecule rather than a simple nested for loop calculates distances in batches between atom i in central molecule and atom ( i - x ) in neighbour returns a dataframe with all atom atom distances < 10A in the crystal structure
def calc_intermolecular_atom_distances(crystal):
    central_molecule, central_idx = crystal.get_central_molecule(return_idx=True)
    central_atom_coords = np.array([atom.coordinates for atom in central_molecule.atoms]) 
    all_atom_coords = []
    for mol in crystal.molecules:
        all_atom_coords.append(np.array([atom.coordinates for atom in mol.atoms]))
    all_atom_coords = np.array(all_atom_coords) 
    dists = []
    mol1s = []
    mol2s = []
    for i, mol_coords in enumerate(all_atom_coords):
        temp_dist = []
        for x in range(len(mol_coords)):
            mol1s += [central_idx]*len(mol_coords)
            mol2s += [i]*len(mol_coords)
            disp = mol_coords - central_atom_coords 
            dist2 = disp[:,0] * disp[:,0] + disp[:,1] * disp[:,1] + disp[:,2] * disp[:,2]
            dist = np.sqrt(dist2) 
            temp_dist.append(dist)
            mol_coords = np.roll(mol_coords,-1,axis=0)
        dists.append(temp_dist)
    dists = np.array(dists) 
    in_atom_order = np.array([dist.flatten('F') for dist in dists]).reshape(-1)
    d1 = dists.shape[0]
    d2 = dists.shape[1]
    arange = np.arange(d2)
    atom1s = np.concatenate([[x]*d2 for x in range(d2)]*d1)
    atom2s = np.concatenate([np.roll(arange,-x) for x in range(d2)]*d1)
    data_dict= {'mol1s':mol1s,'mol2s':mol2s,'atom1s':atom1s,'atom2s':atom2s,'dists':in_atom_order}
    atom_dist_df = pd.DataFrame(data_dict)
    atom_dist_df = atom_dist_df[atom_dist_df.mol1s != atom_dist_df.mol2s]
    atom_dist_df = atom_dist_df.loc[atom_dist_df.dists <= 10]
    return atom_dist_df
def calc_intermolecular_atom_distances ( crystal ) : central_molecule , central_idx = crystal . get_central_molecule ( return_idx = True ) central_atom_coords = np . array ( [ atom . coordinates for atom in central_molecule . atoms ] ) all_atom_coords = [ ] for mol in crystal . molecules : all_atom_coords . append ( np . array ( [ atom . coordinates for atom in mol . atoms ] ) ) all_atom_coords = np . array ( all_atom_coords ) dists = [ ] mol1s = [ ] mol2s = [ ] for i , mol_coords in enumerate ( all_atom_coords ) : temp_dist = [ ] for x in range ( len ( mol_coords ) ) : mol1s += [ central_idx ] * len ( mol_coords ) mol2s += [ i ] * len ( mol_coords ) disp = mol_coords - central_atom_coords dist2 = disp [ : , 0 ] * disp [ : , 0 ] + disp [ : , 1 ] * disp [ : , 1 ] + disp [ : , 2 ] * disp [ : , 2 ] dist = np . sqrt ( dist2 ) temp_dist . append ( dist ) mol_coords = np . roll ( mol_coords , - 1 , axis = 0 ) dists . append ( temp_dist ) dists = np . array ( dists ) in_atom_order = np . array ( [ dist . flatten ( 'F' ) for dist in dists ] ) . reshape ( - 1 ) d1 = dists . shape [ 0 ] d2 = dists . shape [ 1 ] arange = np . arange ( d2 ) atom1s = np . concatenate ( [ [ x ] * d2 for x in range ( d2 ) ] * d1 ) atom2s = np . concatenate ( [ np . roll ( arange , - x ) for x in range ( d2 ) ] * d1 ) data_dict = { 'mol1s' : mol1s , 'mol2s' : mol2s , 'atom1s' : atom1s , 'atom2s' : atom2s , 'dists' : in_atom_order } atom_dist_df = pd . DataFrame ( data_dict ) atom_dist_df = atom_dist_df [ atom_dist_df . mol1s != atom_dist_df . mol2s ] atom_dist_df = atom_dist_df . loc [ atom_dist_df . dists <= 10 ] return atom_dist_df
Calculates all interatomic atom atom distances in a crystal structure
calculates distances on batch between central molecules and a neighbour molecule, rather than a simple
nested for loop
calculates distances in batches between atom i in central molecule and atom (i - x) in neighbour
returns a dataframe with all atom atom distances < 10A in the crystal structure
Calculates all interatomic atom atom distances in a crystal structure calculates distances on batch between central molecules and a neighbour molecule rather than a simple nested for loop calculates distances in batches between atom i in central molecule and atom ( i - x ) in neighbour returns a dataframe with all atom atom distances < 10A in the crystal structure
'''
    Calculates all interatomic atom atom distances in a crystal structure
    calculates distances on batch between central molecules and a neighbour molecule, rather than a simple
    nested for loop
    calculates distances in batches between atom i in central molecule and atom (i - x) in neighbour
    returns a dataframe with all atom atom distances < 10A in the crystal structure
    ''' # Calculate Atom Distances from central molecule # shape = (n_atoms,3) # shape = (n_mols,n_atoms,3)  # shape = (n_atoms,3) # shape = (n_atoms) # shape = (n_molecules,x_atoms,y_atoms) | where y in y_atoms = dist(atom_x_central - atom_y_mol_n) # Put distances in order of atom indices #atom2s = np.concatenate([[x for x in range(d2)]*d2]*d1) # Turn Atom Distances to DataFrame
crystal