diff --git a/modules/gfx/pymod/export_entity.cc b/modules/gfx/pymod/export_entity.cc
index e22578c47f8a7fca5919a5b343ca25204115031b..dd999dcbcd4a3cf262dc7de7b0ea9820cfe53458 100644
--- a/modules/gfx/pymod/export_entity.cc
+++ b/modules/gfx/pymod/export_entity.cc
@@ -120,6 +120,15 @@ void color_by_09(Entity* e,
   e->ColorBy(prop,gradient,selection);
 }
 
+void color_by_10(Entity* e,
+                 const String& prop,
+                 const Gradient& gradient,
+                 float minv, float maxv,
+                 bool clamp)
+{
+  e->ColorBy(prop,gradient,minv,maxv,clamp);
+}
+
 // temporary, see comment in gfx/entity.hh
 void detail_color_by_02(Entity* e,
                         const String& prop, 
@@ -334,6 +343,7 @@ void export_Entity()
     .def("ColorBy", color_by_07)
     .def("ColorBy", color_by_08)
     .def("ColorBy", color_by_09)
+    .def("ColorBy", color_by_10)
     .def("DetailColorBy", detail_color_by_02)
     COLOR_BY_DEF()
     .def("RadiusBy", radius_by_01)
diff --git a/modules/gfx/src/color_ops/gradient_color_op.cc b/modules/gfx/src/color_ops/gradient_color_op.cc
index 192ad563283dbfd5e6b1004718bbb753206715c1..0a9e95952d1eb01c7e45232c887a6f4944dfbf3b 100644
--- a/modules/gfx/src/color_ops/gradient_color_op.cc
+++ b/modules/gfx/src/color_ops/gradient_color_op.cc
@@ -31,7 +31,7 @@ GradientColorOp::GradientColorOp() : ColorOp(), property_(), gradient_(){
 GradientColorOp::GradientColorOp(const String& selection, const String& property,
                                  const gfx::Gradient& gradient, 
                                  float minv, float maxv):
-  ColorOp(selection), property_(property), gradient_(gradient), calculate_(false),
+  ColorOp(selection), property_(property), gradient_(gradient), clamp_(true), calculate_(false),
   minv_(minv), maxv_(maxv)
 {
   this->Init();
@@ -40,7 +40,7 @@ GradientColorOp::GradientColorOp(const String& selection, const String& property
 GradientColorOp::GradientColorOp(const String& selection, int mask, const String& property,
                                  const gfx::Gradient& gradient,
                                  float minv, float maxv):
-  ColorOp(selection,mask), property_(property), gradient_(gradient), calculate_(false),
+  ColorOp(selection,mask), property_(property), gradient_(gradient), clamp_(true), calculate_(false),
   minv_(minv), maxv_(maxv)
 {
   this->Init();
@@ -48,14 +48,14 @@ GradientColorOp::GradientColorOp(const String& selection, int mask, const String
 
 GradientColorOp::GradientColorOp(const String& selection, const String& property,
                                  const gfx::Gradient& gradient):
-  ColorOp(selection), property_(property), gradient_(gradient), calculate_(true)
+  ColorOp(selection), property_(property), gradient_(gradient), clamp_(true), calculate_(true)
 {
   this->Init();
 }
 
 GradientColorOp::GradientColorOp(const String& selection, int mask, const String& property,
                                  const gfx::Gradient& gradient):
-  ColorOp(selection,mask), property_(property), gradient_(gradient), calculate_(true)
+  ColorOp(selection,mask), property_(property), gradient_(gradient), clamp_(true), calculate_(true)
 {
   this->Init();
 }
@@ -63,7 +63,7 @@ GradientColorOp::GradientColorOp(const String& selection, int mask, const String
 GradientColorOp::GradientColorOp(const mol::QueryViewWrapper& query_view, const String& property,
                                  const gfx::Gradient& gradient,
                                  float minv, float maxv):
-  ColorOp(query_view), property_(property), gradient_(gradient), calculate_(false),
+  ColorOp(query_view), property_(property), gradient_(gradient), clamp_(true), calculate_(false),
   minv_(minv), maxv_(maxv)
 {
   this->Init();
@@ -72,7 +72,7 @@ GradientColorOp::GradientColorOp(const mol::QueryViewWrapper& query_view, const
 GradientColorOp::GradientColorOp(const mol::QueryViewWrapper& query_view, int mask, const String& property,
                                  const gfx::Gradient& gradient,
                                  float minv, float maxv):
-  ColorOp(query_view,mask), property_(property), gradient_(gradient), calculate_(false),
+  ColorOp(query_view,mask), property_(property), gradient_(gradient), clamp_(true), calculate_(false),
   minv_(minv), maxv_(maxv)
 {
   this->Init();
@@ -80,14 +80,14 @@ GradientColorOp::GradientColorOp(const mol::QueryViewWrapper& query_view, int ma
 
 GradientColorOp::GradientColorOp(const mol::QueryViewWrapper& query_view, const String& property,
                                  const gfx::Gradient& gradient):
-  ColorOp(query_view), property_(property), gradient_(gradient), calculate_(true)
+  ColorOp(query_view), property_(property), gradient_(gradient), clamp_(true), calculate_(true)
 {
   this->Init();
 }
 
 GradientColorOp::GradientColorOp(const mol::QueryViewWrapper& query_view, int mask, const String& property,
                                  const gfx::Gradient& gradient):
-  ColorOp(query_view,mask), property_(property), gradient_(gradient), calculate_(true)
+  ColorOp(query_view,mask), property_(property), gradient_(gradient), clamp_(true), calculate_(true)
 {
   this->Init();
 }
diff --git a/modules/gfx/src/color_ops/gradient_color_op.hh b/modules/gfx/src/color_ops/gradient_color_op.hh
index c6616e63801d0b63833a21aa02912c875945ef90..9c7f37345e9a6e3f9898d112ad50b8712f18f282 100644
--- a/modules/gfx/src/color_ops/gradient_color_op.hh
+++ b/modules/gfx/src/color_ops/gradient_color_op.hh
@@ -64,10 +64,15 @@ public:
   virtual void ToInfo(info::InfoGroup& group) const;
   static gfx::GradientColorOp FromInfo(info::InfoGroup& group);
 
+  // if true then color with clamped colors outside given range as well
+  void SetClamp(bool f) {clamp_=f;}
+  bool GetClamp() const {return clamp_;}
+
 private:
   void Init();
   String property_;
   gfx::Gradient gradient_;
+  bool clamp_;
   bool calculate_;
   mutable float minv_;
   mutable float maxv_;
diff --git a/modules/gfx/src/entity.cc b/modules/gfx/src/entity.cc
index 959c0312c620deeafa4db4658fac9356603e14ac..b961134f3f60b6f9cbd59e8952a11f75dbd64579 100644
--- a/modules/gfx/src/entity.cc
+++ b/modules/gfx/src/entity.cc
@@ -842,6 +842,16 @@ void Entity::ColorBy(const String& prop,
   this->Apply(glop);
 }
 
+void Entity::ColorBy(const String& prop,
+                     const Gradient& gradient,
+                     float minv,float maxv,
+                     bool clamp)
+{
+  GradientLevelColorOp glop = GradientLevelColorOp("",prop, gradient,minv,maxv,mol::Prop::UNSPECIFIED);
+  glop.SetClamp(clamp);
+  this->Apply(glop);
+}
+
 void Entity::DetailColorBy(const String& prop,
                            const Gradient& gradient,
                            float minv,float maxv,
diff --git a/modules/gfx/src/entity.hh b/modules/gfx/src/entity.hh
index 07a2bd74e08763af1d1840bf65182fec854ea840..49cca7a78775dd981e3afe29823aeca950aadffd 100644
--- a/modules/gfx/src/entity.hh
+++ b/modules/gfx/src/entity.hh
@@ -223,6 +223,12 @@ public:
                float minv,float maxv,
                mol::Prop::Level hint=mol::Prop::UNSPECIFIED);
 
+  // temporarily here, will be moved to py interface
+  void ColorBy(const String& prop, 
+               const Gradient& gradient,
+               float minv,float maxv,
+               bool clamp);
+
   // temporary, should be incorporated with ColorBy
   void DetailColorBy(const String& prop, 
                      const Gradient& gradient,
diff --git a/modules/gfx/src/impl/connect_renderer_base.cc b/modules/gfx/src/impl/connect_renderer_base.cc
index f29443093682a19b1432576a465793a67ab9e6f9..fd70d9968b67270d14c837de128fcbce9a003460 100644
--- a/modules/gfx/src/impl/connect_renderer_base.cc
+++ b/modules/gfx/src/impl/connect_renderer_base.cc
@@ -146,7 +146,7 @@ inline void apply_color_op(ConnectRendererBase* rend, GfxView* v, T1 get_col, co
   }
   for(AtomEntryMap::iterator it=v->atom_map.begin();it!=v->atom_map.end();++it){
     if(view.FindAtom(it->second.atom)){
-      it->second.color=get_col.ColorOfAtom(it->second.atom);
+      it->second.color=get_col.ColorOfAtom(it->second.atom).second;
     }
   }
 };
diff --git a/modules/gfx/src/impl/entity_renderer.hh b/modules/gfx/src/impl/entity_renderer.hh
index 14b2ee00ca32242220c2a270ee2b83e5b1a6e573..f5adc9d630b58d877a63ab214cd34d01fd205a5e 100644
--- a/modules/gfx/src/impl/entity_renderer.hh
+++ b/modules/gfx/src/impl/entity_renderer.hh
@@ -185,46 +185,60 @@ protected:
 
 //Simplify color ops
 struct ByElementGetCol {
-  Color ColorOfAtom(mol::AtomHandle& atom) const{
-    return GfxObj::Ele2Color(atom.GetElement());
+  std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
+    return std::make_pair(true,GfxObj::Ele2Color(atom.GetElement()));
   }
 };
 
 struct ByChainGetCol {
   ByChainGetCol(const ByChainColorOp& op):op_(op){}
-  Color ColorOfAtom(mol::AtomHandle& atom) const{
-    return op_.GetColor(atom.GetResidue().GetChain().GetName());
+  std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
+    return std::make_pair(true,op_.GetColor(atom.GetResidue().GetChain().GetName()));
   }
   const ByChainColorOp& op_;
 };
 
 struct UniformGetCol {
   UniformGetCol(const Color& col):col_(col){ }
-  Color ColorOfAtom(mol::AtomHandle& atom) const{
-    return col_;
+  std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
+    return std::make_pair(true,col_);
   }
   const Color& col_;
 };
 
 struct GradientLevelGetCol {
-  GradientLevelGetCol(const GradientLevelColorOp& op): property_(op.GetProperty()),
-      epm_(property_, op.GetLevel()),
-      gradient_(op.GetGradient()),
-      minv_(op.GetMinV()),
-      maxv_(op.GetMaxV()){}
-  Color ColorOfAtom(mol::AtomHandle& atom) const{
+  GradientLevelGetCol(const GradientLevelColorOp& op):
+    property_(op.GetProperty()),
+    epm_(property_, op.GetLevel()),
+    gradient_(op.GetGradient()),
+    minv_(op.GetMinV()),
+    maxv_(op.GetMaxV()),
+    clamp_(op.GetClamp())
+  {}
+  std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
     try{
-      float n=Normalize(epm_.Get(atom, minv_), minv_, maxv_);
-      return gradient_.GetColorAt(n);
+      float r = epm_.Get(atom, minv_);
+      if(clamp_) {
+        float n=Normalize(r, minv_, maxv_);
+        return std::make_pair(true,gradient_.GetColorAt(n));
+      } else {
+        if(r>=minv_ && r<=maxv_) {
+          float n=Normalize(r, minv_, maxv_);
+          return std::make_pair(true,gradient_.GetColorAt(n));
+        } else {
+          return std::make_pair(false,Color());
+        }
+      }
     }catch(std::exception&){
       LOG_DEBUG("property " << property_ << " not found");
-      return Color();
+      return std::make_pair(false,Color());
     }
   }
   String property_;
   mol::EntityPropertyMapper epm_;
   Gradient gradient_;
   float minv_, maxv_;
+  bool clamp_;
 };
 
 struct EntityViewGetCol {
@@ -233,8 +247,8 @@ struct EntityViewGetCol {
       gradient_(op.GetGradient()),
       minv_(op.GetMinV()),
       maxv_(op.GetMaxV()){}
-  Color ColorOfAtom(mol::AtomHandle& atom) const{
-    return MappedProperty(ev_,property_,gradient_,minv_,maxv_,atom.GetPos());
+  std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
+    return std::make_pair(true,MappedProperty(ev_,property_,gradient_,minv_,maxv_,atom.GetPos()));
   }
   String property_;
   mol::EntityView ev_;
@@ -249,8 +263,8 @@ struct MapHandleGetCol {
       gradient_(op.GetGradient()),
       minv_(op.GetMinV()),
       maxv_(op.GetMaxV()){}
-  Color ColorOfAtom(mol::AtomHandle& atom) const{
-    return MappedProperty(mh_,property_,gradient_,minv_,maxv_,atom.GetPos());
+  std::pair<bool,Color> ColorOfAtom(mol::AtomHandle& atom) const{
+    return std::make_pair(true,MappedProperty(mh_,property_,gradient_,minv_,maxv_,atom.GetPos()));
   }
   String property_;
   img::MapHandle mh_;
diff --git a/modules/gfx/src/impl/trace_renderer_base.cc b/modules/gfx/src/impl/trace_renderer_base.cc
index 443321cc515b3570d715d36e46871ea5aff69e87..b77b426913f5aaab3628371554d842e0d31932c6 100644
--- a/modules/gfx/src/impl/trace_renderer_base.cc
+++ b/modules/gfx/src/impl/trace_renderer_base.cc
@@ -50,8 +50,10 @@ inline void apply_color_op(TraceRendererBase* rend, BackboneTrace& trace_subset,
       for (unsigned int i=0; i<nl.size();++i) {
         if(nl[i].atom.IsValid()) {
           if (q.IsAtomSelected(nl[i].atom)) {
-            Color clr =get_col.ColorOfAtom(nl[i].atom);
-            set_node_entry_color(nl[i],mask,clr);
+            std::pair<bool,Color> clr =get_col.ColorOfAtom(nl[i].atom);
+            if(clr.first) {
+              set_node_entry_color(nl[i],mask,clr.second);
+            }
           }
         }
       }
@@ -62,8 +64,10 @@ inline void apply_color_op(TraceRendererBase* rend, BackboneTrace& trace_subset,
       NodeEntryList& nl=trace_subset.GetList(node_list);
       for (unsigned int i=0; i<nl.size();++i) {
         if(view.FindAtom(nl[i].atom)){
-          Color clr =get_col.ColorOfAtom(nl[i].atom);
-          set_node_entry_color(nl[i],mask,clr);
+          std::pair<bool,Color> clr =get_col.ColorOfAtom(nl[i].atom);
+          if(clr.first) {
+            set_node_entry_color(nl[i],mask,clr.second);
+          }
         }
       }
     }