# Criterion for a subvariety to be affine?

Say $X$ is an algebraic variety and $U\subset X$ is open. Consider the natural map $U\rightarrow \operatorname{Spm}(\mathcal{O}_X(U))$ given by sending a point of $U$ to the ideal of sections over $U$ that vanish on that point. $U$ is affine if and only if this map is an isomorphism of varieties.

Is it enough to know $U$ is a bijection of sets? (It seems to me it should be! The ring of global sections on $\operatorname{Spm}(\mathcal{O}_X(U))$ is already $\mathcal{O}_X(U)$ right? So the rings already match! We just need to check that the sets match... what am I missing?)

EDIT (in response to comments by QiL):

First, let me add the assumption that $\mathcal{O}_X(U)$ is finitely generated as a $k$-algebra, so that $\operatorname{Spm}(\mathcal{O}_X(U))$ is an affine variety.

Second, let me state the definition of algebraic variety I'm working with: a separated prevariety. A prevariety is a quasicompact topological space with a sheaf of $k$-valued functions (for $k$ some algebraically closed field) such that every point is contained in an open set such that the restriction of the sheaf to that set makes it isomorphic (as a ringed space) to an affine variety. An affine variety is the $\operatorname{Spm}$ of a finitely generated reduced $k$-algebra.

-
Well, in principle you have to check that the topologies match as well... – Zhen Lin Nov 6 '12 at 21:25
@ZhenLin - my idea was that the topology is basically coming from the ring... – Ben Blum-Smith Nov 12 '12 at 0:26

First you should probably work with Spec rather that Spm because $O_X(U)$ in general is not a finitely generated algebra and you can't call Spm$(O_X(U))$ an algebraic variety.
Working with Spec, there is a lemma in Stack project (23.14.4 in my version) which says that if $U$ is quasi-affine, then $U\to \mathrm{Spec}(O_X(U))$ is always an open immersion (and the converse is quasi-true). So under your hypothesis it is an isomorphism and $U$ is affine.
Suppose I add the assumption that $\mathcal{O}_X(U)$ is finitely generated? Then $\operatorname{Spm}\mathcal{O}_X(U)$ is a variety. It seems to me that the map $U\rightarrow \mathcal{O}_X(U)$ will automatically be well-defined because the sections over $U$ already include constant functions, so the quotient of $\mathcal{O}_X(U)$ by the ideal of sections vanishing at $p\in U$ will always be the ground field. Now if it is a bijection, then I have two varieties with a correspondence between the points that pulls back to an isomorphism of global sections. Is this enough? – Ben Blum-Smith Nov 11 '12 at 23:08
@BenBlum-Smith: if $O_X(U)$ is finite type over the ground field, then yes your map is a well defined morphism of varieties. If $U$ is moreover quasi-affine, then you morphism is an isomorphism. Otherwise, I don't know. Also please define "algebraic variety". – user18119 Nov 12 '12 at 9:40