Skip to content

Commit

Permalink
Changes to molecule/draw.py
Browse files Browse the repository at this point in the history
These don't seem to be catalyst-specific.
(Though will be helpful for ones that are)
  • Loading branch information
rwest committed Jan 25, 2019
1 parent 60a197f commit 71a2db6
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions rmgpy/molecule/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,27 +307,31 @@ def __generateCoordinates(self):
"""
atoms = self.molecule.atoms
Natoms = len(atoms)
flag_charge = 0

for atom in self.molecule.atoms:
if atom.charge != 0:
flag_charge = 1
break


# Initialize array of coordinates
self.coordinates = coordinates = numpy.zeros((Natoms, 2))

if flag_charge == 1:
# If there are only one or two atoms to draw, then determining the
# coordinates is trivial
if Natoms == 1:
self.coordinates[0,:] = [0.0, 0.0]
return self.coordinates
elif Natoms == 2:
self.coordinates[0,:] = [-0.5, 0.0]
self.coordinates[1,:] = [0.5, 0.0]
return self.coordinates


# If there are only one or two atoms to draw, then determining the
# coordinates is trivial
if Natoms == 1:
self.coordinates[0, :] = [0.0, 0.0]
return self.coordinates
elif Natoms == 2:
self.coordinates[0, :] = [-0.5, 0.0]
self.coordinates[1, :] = [0.5, 0.0]
return self.coordinates

# Decide whether we can use RDKit or have to generate coordinates ourselves
for atom in self.molecule.atoms:
if atom.charge != 0:
useRDKit = False
break
else: # didn't break
useRDKit = True

if not useRDKit:
if len(self.cycles) > 0:
# Cyclic molecule
backbone = self.__findCyclicBackbone()
Expand Down Expand Up @@ -376,8 +380,7 @@ def __generateCoordinates(self):
return coordinates

else:

# Use rdkit 2D coordinate generation:
# Use RDKit 2D coordinate generation:

# Generate the RDkit molecule from the RDkit molecule, use geometry
# in order to match the atoms in the rdmol with the atoms in the
Expand All @@ -391,7 +394,7 @@ def __generateCoordinates(self):
for atom in atoms:
index = rdAtomIdx[atom]
point = rdmol.GetConformer(0).GetAtomPosition(index)
coordinates[index,:]= [point.x*0.6, point.y*0.6]
coordinates[index,:] = [point.x*0.6, point.y*0.6]

# RDKit generates some molecules more vertically than horizontally,
# Especially linear ones. This will reflect any molecule taller than
Expand Down

0 comments on commit 71a2db6

Please sign in to comment.