Let $X$ be a topological space. For every point $x \in X$ let $R\_x$ be a local ring. Under what (necessary / sufficient / necessary and sufficient) conditions is there a sheaf ${\cal O}\_X$ such that $(X,\mathcal{O}\_X)$ is a locally ringed space with $\mathcal{O}\_{X,x} \cong R\_x$ for all $x \in X$?


If $X$ is discrete, we need no conditions, and we can take the sheaf $\mathcal{O}\_X(U)=\prod\_{x \in U} R\_x$. But in general, a necessary condition is that $x \prec y$ gives a ring homomorphism $R\_x \to R\_y$, and that these are compatible in the sense that $x \mapsto R\_x$ extends to a functor from the specialization preorder of $X$ to the category of rings. We will also have $\mathcal{O}\_X(U) \subseteq \varprojlim\_{x \in U} R\_x$, but probably no equality.



Families of local rings coming from a locally ringed space
Here is another necessary condition for the existence of such a sheaf:



> 
> For all $x \in X$ and for all $f \in R\_x$, there exists a neighborhood $U$ of $x$ such that the $f$ is contained in the image of the canonical homomorphism $$\varprojlim\_{y \in U} R\_y \to R\_x.$$
> 
> 
> 


For suppose that such a sheaf $\mathcal{O}$ exists and let let $f \in R\_x$. By definition of the stalk $\mathcal{O}\_x$, there exists a neighborhood $U$ of $x$ such that $f$ is in the image of $\mathcal{O}(U) \to \mathcal{O}\_x \cong R\_x$. But as you indicate above, this factors through the natural map $\varprojlim\_{y \in U} R\_y \to R\_x$, whence $f$ is in the image of the latter homomorphism.


I can't see at the moment whether this is a sufficient condition. My temptation would be to assume that this condition holds and construct a (pre?)sheaf $\mathcal{O}$ by $\mathcal{O}(U) = \varprojlim\_{x \in U} R\_x$. (Even if this isn't a sheaf, which I'm too lazy/busy to check right now, its sheafification will have the same stalks.) Is this condition enough to ensure that $\mathcal{O}\_x \cong R\_x$? If not, is there some simple condition that may be added to guarantee this isomorphism?


**Edit:** As pointed out by Martin in the comments, assuming the condition above, the sheaf defined by $\mathcal{O}(U) = \varprojlim\_{x \in U} R\_x$ is constructed in such a way that there are natural surjections $\mathcal{O}\_x \twoheadrightarrow R\_x$. To make the necessary condition sufficient, we only need to ensure that these surjections are also injective. This can be prhased by demanding, for all $x$, that $$\varinjlim\_{\mbox{open }U \ni x} \left( \varprojlim\_{y \in U} R\_y \right) \to R\_x$$ is an isomorphism. 


Alternatively, injectivity of the maps may be obtained via the following condition (which is also necessary):



> 
> For all $x \in X$ and every open neighborhood $U$ of $x$, if $g \in \varprojlim\_{y \in U} R\_y$ is in the kernel of $\varprojlim\_{y \in U} R\_y \to R\_x$, then there exists a neighborhood $V \subseteq U$ of $x$ such that $g$ is in the kernel of the natural map $\varprojlim\_{y \in U} R\_y \to \varprojlim\_{y \in V} R\_y$.
> 
> 
> 


