Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/materialsproject/pymatgen
Browse files Browse the repository at this point in the history
  • Loading branch information
xhqu1981 committed Jul 18, 2013
2 parents cb7b05e + db2ca4e commit 2372990
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 20 deletions.
9 changes: 4 additions & 5 deletions pymatgen/symmetry/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,6 @@ def get_symmetry_operations(self, cartesian=False):
symmops.append(op)
return symmops


def get_point_group_operations(self, cartesian=False):
"""
Return symmetry operations as a list of SymmOp objects.
Expand All @@ -287,10 +286,10 @@ def get_point_group_operations(self, cartesian=False):
for rot, trans in zip(rotation, translation):
if cartesian:
rot = np.dot(mat, np.dot(rot, invmat))
trans = np.dot(trans, self._structure.lattice.matrix)
op = SymmOp.from_rotation_and_translation(rot, np.array([0,0,0]))
op = SymmOp.from_rotation_and_translation(rot, np.array([0, 0, 0]))
symmops.append(op)
return symmops

def get_symmetrized_structure(self):
"""
Get a symmetrized structure. A symmetrized structure is one where the
Expand Down Expand Up @@ -351,8 +350,8 @@ def find_primitive(self):
species = [self._unique_species[i - 1] for i in zs]

if num_atom_prim > 0:
return Structure(lattice.T, species, positions[:num_atom_prim],to_unit_cell=True)\
.get_reduced_structure()
return Structure(lattice.T, species, positions[:num_atom_prim],
to_unit_cell=True).get_reduced_structure()
else:
#Not sure if we should return None or just return the full
#structure.
Expand Down
29 changes: 20 additions & 9 deletions pymatgen/transformations/standard_transformations.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,14 +301,17 @@ def __init__(self, species_map):
"""
Args:
species_map:
A dict containing the species mapping in string-string pairs.
E.g., { "Li":"Na"} or {"Fe2+","Mn2+"}. Multiple substitutions
can be done. Overloaded to accept sp_and_occu dictionary
E.g. {"Si: {"Ge":0.75, "C":0.25} }, which substitutes a single
species with multiple species to generate a disordered
structure.
"""
self._species_map = species_map
A dict or list of tuples containing the species mapping in
string-string pairs. E.g., {"Li":"Na"} or [("Fe2+","Mn2+")].
Multiple substitutions can be done. Overloaded to accept
sp_and_occu dictionary E.g. {"Si: {"Ge":0.75, "C":0.25}},
which substitutes a single species with multiple species to
generate a disordered structure.
"""
self._species_map = dict(species_map)
for k, v in self._species_map.iteritems():
if isinstance(v, (tuple, list)):
self._species_map[k] = dict(v)

def apply_transformation(self, structure):
species_map = {}
Expand Down Expand Up @@ -341,7 +344,15 @@ def is_one_to_many(self):

@property
def to_dict(self):
sp_map = {str(k):str(v) for k, v in self._species_map.iteritems()}
#convert sp_map to tuple representation to work with Mongo
#which doesn't allow '.' in key names
sp_map = []
for k, v in self._species_map.iteritems():
if isinstance(v, dict):
v = [(str(k2), v2) for k2, v2 in v.iteritems()]
sp_map.append((str(k), v))
else:
sp_map.append((str(k), v))
return {"name": self.__class__.__name__, "version": __version__,
"init_args": {"species_map": sp_map},
"@module": self.__class__.__module__,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ def test_apply_transformation(self):
def test_fractional_substitution(self):
t = SubstitutionTransformation({"Li+": "Na+",
"O2-": {"S2-": 0.5, "Se2-": 0.5}})
#test the to and from dict on the nested dictionary
t = SubstitutionTransformation.from_dict(t.to_dict)
coords = list()
coords.append([0, 0, 0])
coords.append([0.75, 0.75, 0.75])
Expand Down
116 changes: 110 additions & 6 deletions pymatgen/vis/structure_vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,9 @@ def add_line(self, start, end, color=(0.5, 0.5, 0.5), width=1):
actor.GetProperty().SetLineWidth(width)
self.ren.AddActor(actor)

def add_polyhedron(self, neighbors, center, color):
def add_polyhedron(self, neighbors, center, color, opacity=0.4,
draw_edges=False, edges_color=[0.0, 0.0, 0.0],
edges_linewidth=2):
"""
Adds a polyhedron.
Expand All @@ -448,6 +450,14 @@ def add_polyhedron(self, neighbors, center, color):
The atom in the center of the polyhedron.
color:
Color for text as RGB.
opacity:
Opacity of the polyhedron
draw_edges:
If set to True, the a line will be drawn at each edge
edges_color:
Color of the line for the edges
edges_linewidth:
Width of the line drawn for the edges
"""
points = vtk.vtkPoints()
conv = vtk.vtkConvexPointSet()
Expand All @@ -464,15 +474,99 @@ def add_polyhedron(self, neighbors, center, color):
polysites = [center]
polysites.extend(neighbors)
self.mapper_map[dsm] = polysites
dsm.SetInputData(grid)
if vtk.VTK_MAJOR_VERSION <= 5:
dsm.SetInputConnection(grid.GetProducerPort())
else:
dsm.SetInputData(grid)
ac = vtk.vtkActor()
#ac.SetMapper(mapHull)
ac.SetMapper(dsm)
ac.GetProperty().SetOpacity(0.4)
ac.GetProperty().SetColor(color)
ac.GetProperty().SetOpacity(opacity)
if color == 'element':
# If partial occupations are involved, the color of the specie with
# the highest occupation is used
myoccu = 0.0
for specie, occu in center.species_and_occu.items():
if occu > myoccu:
myspecie = specie
myoccu = occu
color = [i / 255 for i in self.el_color_mapping[myspecie.symbol]]
ac.GetProperty().SetColor(color)
else:
ac.GetProperty().SetColor(color)
if draw_edges:
ac.GetProperty().SetEdgeColor(edges_color)
ac.GetProperty().SetLineWidth(edges_linewidth)
ac.GetProperty().EdgeVisibilityOn()
self.ren.AddActor(ac)

def add_bonds(self, neighbors, center):
def add_triangle(self, neighbors, color, center=None, opacity=0.4,
draw_edges=False, edges_color=[0.0, 0.0, 0.0],
edges_linewidth=2):
"""
Adds a triangular surface between three atoms.
Args:
atoms:
Atoms between which a triangle will be drawn.
color:
Color for triangle as RGB.
center:
The "central atom" of the triangle
opacity:
opacity of the triangle
draw_edges:
If set to True, the a line will be drawn at each edge
edges_color:
Color of the line for the edges
edges_linewidth:
Width of the line drawn for the edges
"""
points = vtk.vtkPoints()
triangle = vtk.vtkTriangle()
for ii in range(3):
points.InsertNextPoint(neighbors[ii].x, neighbors[ii].y,
neighbors[ii].z)
triangle.GetPointIds().SetId(ii,ii)
triangles = vtk.vtkCellArray()
triangles.InsertNextCell(triangle)

# polydata object
trianglePolyData = vtk.vtkPolyData()
trianglePolyData.SetPoints( points )
trianglePolyData.SetPolys( triangles )

# mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInput(trianglePolyData)

ac = vtk.vtkActor()
ac.SetMapper(mapper)
ac.GetProperty().SetOpacity(opacity)
if color == 'element':
if center is None:
raise ValueError(
'Color should be chosen according to the central atom, '
'and central atom is not provided')
# If partial occupations are involved, the color of the specie with
# the highest occupation is used
myoccu = 0.0
for specie, occu in center.species_and_occu.items():
if occu > myoccu:
myspecie = specie
myoccu = occu
color = [i / 255 for i in self.el_color_mapping[myspecie.symbol]]
ac.GetProperty().SetColor(color)
else:
ac.GetProperty().SetColor(color)
if draw_edges:
ac.GetProperty().SetEdgeColor(edges_color)
ac.GetProperty().SetLineWidth(edges_linewidth)
ac.GetProperty().EdgeVisibilityOn()
self.ren.AddActor(ac)

def add_bonds(self, neighbors, center, color=None, opacity=None,
radius=0.1):
"""
Adds bonds for a site.
Expand All @@ -481,6 +575,12 @@ def add_bonds(self, neighbors, center):
Neighbors of the site.
center:
The site in the center for all bonds.
color:
Color of the tubes representing the bonds
opacity:
Opacity of the tubes representing the bonds
radius:
radius of tube s representing the bonds
"""
points = vtk.vtkPoints()
points.InsertPoint(0, center.x, center.y, center.z)
Expand All @@ -497,13 +597,17 @@ def add_bonds(self, neighbors, center):

tube = vtk.vtkTubeFilter()
tube.SetInput(pd)
tube.SetRadius(0.1)
tube.SetRadius(radius)

mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(tube.GetOutputPort())

actor = vtk.vtkActor()
actor.SetMapper(mapper)
if opacity is not None:
actor.GetProperty().SetOpacity(opacity)
if color is not None:
actor.GetProperty().SetColor(color)
self.ren.AddActor(actor)

def add_picker_fixed(self):
Expand Down

0 comments on commit 2372990

Please sign in to comment.