Skip to content

Commit

Permalink
add from_numpy fn
Browse files Browse the repository at this point in the history
  • Loading branch information
li012589 committed Aug 28, 2019
1 parent e4d263e commit 3a7ce43
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions mogli.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,19 +372,25 @@ def read(file_name, file_format=None):
raise UnknownFileFormatException(message)

def load(file_name,name,smile,scaling=10,fix=np.array([0,0,0])):
molecules = []
with np.load(file_name) as data:
positions = data[name].reshape(-1,3)*scaling
positions[:,:] = positions[:,:]-fix
return from_numpy(positions,smile)

def from_numpy(array,smile):
"""
array must be of [n,3]
"""
smiles = []
for cha in smile:
if cha.isalpha():
smiles.append(cha)
N = len(smiles)
with np.load(file_name) as data:
positions = data[name].reshape(-1,N,3)*scaling
positions[:,:] = positions[:,:]-fix
array = array.reshape(-1,N,3)
atomic_numbers = [ATOM_NUMBERS[atom_string] for atom_string in smiles]
for i in range(positions.shape[0]):
molecules.append(Molecule(atomic_numbers,positions[i]))

molecules = []
for i in range(array.shape[0]):
molecules.append(Molecule(atomic_numbers,array[i]))
return molecules


Expand Down

0 comments on commit 3a7ce43

Please sign in to comment.